From 1aec224fdfa0cfbc4582a555c5d315b481deeb8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alois=20Se=C4=8Dk=C3=A1r?= Date: Sun, 21 Jul 2024 19:59:40 +0200 Subject: [PATCH] #247 - refactor usePageMeta --- app.vue | 51 ++++++++++++++++++++++---------------- composables/usePageMeta.ts | 20 ++++++++++++--- pages/help.vue | 7 ------ pages/index.vue | 2 -- pages/project.vue | 7 ------ pages/report.vue | 7 ------ 6 files changed, 47 insertions(+), 47 deletions(-) diff --git a/app.vue b/app.vue index c6e8cc5..b0d3f5c 100644 --- a/app.vue +++ b/app.vue @@ -1,28 +1,28 @@ @@ -43,6 +43,15 @@ useHead({ }, }) +const title = ref(getPageTitle(useRoute().path)) +usePageMeta({ + ...WBSC_PAGE_META, + title, +}) +useRouter().beforeEach((to) => { + title.value = getPageTitle(to.path) +}) + function toIndex() { return navigateTo('/') } diff --git a/composables/usePageMeta.ts b/composables/usePageMeta.ts index 0836c69..6bc2902 100644 --- a/composables/usePageMeta.ts +++ b/composables/usePageMeta.ts @@ -5,9 +5,9 @@ export const WBSC_DSCR = 'Visualization of WBSC baseball/softball scoring system export type MetaDef = { type?: 'website' | 'article' - url?: string - title?: string - dscr?: string + url?: string | Ref + title?: string | Ref + dscr?: string | Ref } export const WBSC_PAGE_META: MetaDef = { @@ -29,3 +29,17 @@ export function usePageMeta(meta: MetaDef) { twitterCard: 'summary_large_image', }) } + +export function getPageTitle(route: string) { + const title = WBSC_TITLE + switch (route) { + case '/help': + return title + ' - Help' + case '/project': + return title + ' - Project' + case '/report': + return title + ' - Report' + default: + return title + } +} diff --git a/pages/help.vue b/pages/help.vue index f279797..688eada 100644 --- a/pages/help.vue +++ b/pages/help.vue @@ -4,10 +4,3 @@ - - diff --git a/pages/index.vue b/pages/index.vue index 9d5f9bc..17d4e55 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -55,8 +55,6 @@ import type { WBSCToolbar } from '#components' const version = 'v' + useAppConfig().publicVersion -usePageMeta(WBSC_PAGE_META) - const toolbar: Ref | null> = ref(null) onMounted(() => toolbar.value?.init()) diff --git a/pages/project.vue b/pages/project.vue index 112909a..57afe8b 100644 --- a/pages/project.vue +++ b/pages/project.vue @@ -4,10 +4,3 @@ - - diff --git a/pages/report.vue b/pages/report.vue index f2de0e5..30581d1 100644 --- a/pages/report.vue +++ b/pages/report.vue @@ -4,10 +4,3 @@ - -