-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from IT4Change/per-page-title
feat(frontend): per page title
- Loading branch information
Showing
21 changed files
with
172 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# META | ||
PUBLIC_ENV__META__DEFAULT_TITLE="IT4C" | ||
PUBLIC_ENV__META__DEFAULT_DESCRIPTION="IT4C Frontend Boilerplate" | ||
PUBLIC_ENV__META__BASE_URL="http://localhost:3000" | ||
PUBLIC_ENV__META__DEFAULT_AUTHOR="IT Team 4 Change" | ||
PUBLIC_ENV__META__DEFAULT_DESCRIPTION="IT4C Frontend Boilerplate" | ||
PUBLIC_ENV__META__DEFAULT_TITLE="IT4C" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import { createApp } from './app' | ||
import { PageContext } from 'vike/types' | ||
|
||
import type { PageContext, VikePageContext } from '#types/PageContext' | ||
import { createApp } from './app' | ||
import { getTitle } from './utils' | ||
|
||
let instance: ReturnType<typeof createApp> | ||
/* async */ function render(pageContext: VikePageContext & PageContext) { | ||
/* async */ function render(pageContext: PageContext) { | ||
if (!instance) { | ||
instance = createApp(pageContext) | ||
instance.app.mount('#app') | ||
} else { | ||
instance.app.changePage(pageContext) | ||
} | ||
|
||
document.title = getTitle(pageContext) | ||
} | ||
|
||
export default render |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { PageContext } from 'vike/types' | ||
|
||
import { META } from '#src/env' | ||
|
||
function getTitle(pageContext: PageContext) { | ||
// The value exported by /pages/**/+title.js is available at pageContext.config.title | ||
const val = pageContext.config.title | ||
if (typeof val === 'string') return val | ||
if (typeof val === 'function') return String(val(pageContext)) | ||
return META.DEFAULT_TITLE | ||
} | ||
function getDescription(pageContext: PageContext) { | ||
const val = pageContext.config.description | ||
if (typeof val === 'string') return val | ||
if (typeof val === 'function') return val(pageContext) | ||
return META.DEFAULT_DESCRIPTION | ||
} | ||
|
||
export { getTitle, getDescription } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
const META = { | ||
DEFAULT_TITLE: (import.meta.env.PUBLIC_ENV__META__DEFAULT_TITLE as string) ?? 'IT4C', | ||
DEFAULT_DESCRIPTION: | ||
(import.meta.env.PUBLIC_ENV__META__DEFAULT_DESCRIPTION as string) ?? | ||
'IT4C Frontend Boilerplate', | ||
BASE_URL: (import.meta.env.PUBLIC_ENV__META__BASE_URL ?? 'http://localhost:3000') as string, | ||
DEFAULT_AUTHOR: (import.meta.env.PUBLIC_ENV__META__DEFAULT_AUTHOR ?? | ||
'IT Team 4 Change') as string, | ||
DEFAULT_DESCRIPTION: (import.meta.env.PUBLIC_ENV__META__DEFAULT_DESCRIPTION ?? | ||
'IT4C Frontend Boilerplate') as string, | ||
DEFAULT_TITLE: (import.meta.env.PUBLIC_ENV__META__DEFAULT_TITLE ?? 'IT4C') as string, | ||
} | ||
|
||
export { META } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const title = 'IT4C | Error' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,74 @@ | ||
import { VueWrapper, mount } from '@vue/test-utils' | ||
import { mount } from '@vue/test-utils' | ||
import { describe, it, expect, beforeEach } from 'vitest' | ||
import { ComponentPublicInstance } from 'vue' | ||
import { Component, h } from 'vue' | ||
import { VApp } from 'vuetify/components' | ||
|
||
import ErrorPage from './+Page.vue' | ||
import { title } from './+title' | ||
|
||
describe('ErrorPage', () => { | ||
let wrapper: VueWrapper<unknown, ComponentPublicInstance<unknown, Omit<unknown, never>>> | ||
const Wrapper = () => { | ||
return mount(ErrorPage) | ||
} | ||
|
||
beforeEach(() => { | ||
wrapper = Wrapper() | ||
it('title returns correct title', () => { | ||
expect(title).toBe('IT4C | Error') | ||
}) | ||
describe('500 Error', () => { | ||
const WrapperUndefined = () => { | ||
return mount(VApp, { | ||
slots: { | ||
default: h(ErrorPage as Component), | ||
}, | ||
}) | ||
} | ||
const WrapperFalse = () => { | ||
return mount(VApp, { | ||
slots: { | ||
default: h(ErrorPage as Component, { | ||
is404: false, | ||
}), | ||
}, | ||
}) | ||
} | ||
|
||
describe('no is404 property set', () => { | ||
it('renders error 500', () => { | ||
expect(wrapper.find('h1').text()).toEqual("$t('error.500.h1')") | ||
expect(wrapper.find('p').text()).toEqual("$t('error.500.text')") | ||
let wrapper: ReturnType<typeof WrapperUndefined> | ||
beforeEach(() => { | ||
wrapper = WrapperUndefined() | ||
}) | ||
}) | ||
|
||
describe('is404 property is false', () => { | ||
beforeEach(async () => { | ||
await wrapper.setProps({ | ||
is404: false, | ||
describe('no is404 property set', () => { | ||
it('renders error 500', () => { | ||
expect(wrapper.find('h1').text()).toEqual("$t('error.500.h1')") | ||
expect(wrapper.find('p').text()).toEqual("$t('error.500.text')") | ||
}) | ||
}) | ||
|
||
it('renders error 500', () => { | ||
expect(wrapper.find('h1').text()).toEqual("$t('error.500.h1')") | ||
expect(wrapper.find('p').text()).toEqual("$t('error.500.text')") | ||
describe('is404 property is false', () => { | ||
beforeEach(() => { | ||
wrapper = WrapperFalse() | ||
}) | ||
|
||
it('renders error 500', () => { | ||
expect(wrapper.find('h1').text()).toEqual("$t('error.500.h1')") | ||
expect(wrapper.find('p').text()).toEqual("$t('error.500.text')") | ||
}) | ||
}) | ||
}) | ||
|
||
describe('is404 property is true', () => { | ||
beforeEach(async () => { | ||
await wrapper.setProps({ | ||
is404: true, | ||
describe('404 Error', () => { | ||
const Wrapper = () => { | ||
return mount(VApp, { | ||
slots: { | ||
default: h(ErrorPage as Component, { | ||
is404: true, | ||
}), | ||
}, | ||
}) | ||
} | ||
let wrapper: ReturnType<typeof Wrapper> | ||
beforeEach(() => { | ||
wrapper = Wrapper() | ||
}) | ||
|
||
it('renders error 400', () => { | ||
expect(wrapper.find('h1').text()).toEqual("$t('error.404.h1')") | ||
expect(wrapper.find('p').text()).toEqual("$t('error.404.text')") | ||
describe('is404 property is true', () => { | ||
it('renders error 400', () => { | ||
expect(wrapper.find('h1').text()).toEqual("$t('error.404.h1')") | ||
expect(wrapper.find('p').text()).toEqual("$t('error.404.text')") | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const title = 'IT4C | About' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const title = 'IT4C | App' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { META } from '#src/env' | ||
|
||
export const title = META.DEFAULT_TITLE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.