Skip to content

Commit

Permalink
#247 - refactor usePageMeta
Browse files Browse the repository at this point in the history
  • Loading branch information
AloisSeckar committed Jul 21, 2024
1 parent 87e2491 commit 1aec224
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 47 deletions.
51 changes: 30 additions & 21 deletions app.vue
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
<template>
<div id="top" class="flex justify-center">
<div class="mx-2 md:w-4/5">
<LanguageSelector />
<div class="text-center">
<header class="mt-1 mb-2">
<h1 class="cursor-pointer" @click="toIndex">
WBSC Scoring <span class="text-red-500">Creator</span>
</h1>
</header>
<!-- <ClientOnly> -->
<div class="text-left sm:text-justify mb-16">
<NuxtPage />
<ClientOnly>
<LanguageSelector />
<div class="text-center">
<header class="mt-1 mb-2">
<h1 class="cursor-pointer" @click="toIndex">
WBSC Scoring <span class="text-red-500">Creator</span>
</h1>
</header>
<div class="text-left sm:text-justify mb-16">
<NuxtPage />
</div>
<footer class="fixed bottom-0 left-0 w-full p-1 bg-wbsc-blue text-black text-xs">
{{ $t('footer.creator') }}
<NuxtLink to="http://alois-seckar.cz" class="text-white hover:text-yellow-300">
Alois Sečkár
</NuxtLink>
(2019-{{ new Date().getFullYear() }})
{{ $t('footer.version') }}
<strong>{{ useAppConfig().fullVersion }}</strong>
</footer>
</div>
<footer class="fixed bottom-0 left-0 w-full p-1 bg-wbsc-blue text-black text-xs">
{{ $t('footer.creator') }}
<NuxtLink to="http://alois-seckar.cz" class="text-white hover:text-yellow-300">
Alois Sečkár
</NuxtLink>
(2019-{{ new Date().getFullYear() }})
{{ $t('footer.version') }}
<strong>{{ useAppConfig().fullVersion }}</strong>
</footer>
<!-- </ClientOnly> -->
</div>
</ClientOnly>
</div>
</div>
</template>
Expand All @@ -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('/')
}
Expand Down
20 changes: 17 additions & 3 deletions composables/usePageMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>
title?: string | Ref<string>
dscr?: string | Ref<string>
}

export const WBSC_PAGE_META: MetaDef = {
Expand All @@ -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
}
}
7 changes: 0 additions & 7 deletions pages/help.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,3 @@
<NavButtons />
</div>
</template>

<script setup lang="ts">
usePageMeta({
...WBSC_PAGE_META,
title: WBSC_PAGE_META.title + ' - Help',
})
</script>
2 changes: 0 additions & 2 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ import type { WBSCToolbar } from '#components'

const version = 'v' + useAppConfig().publicVersion

usePageMeta(WBSC_PAGE_META)

const toolbar: Ref<InstanceType<typeof WBSCToolbar> | null> = ref(null)
onMounted(() => toolbar.value?.init())
</script>
7 changes: 0 additions & 7 deletions pages/project.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,3 @@
<NavButtons />
</div>
</template>

<script setup lang="ts">
usePageMeta({
...WBSC_PAGE_META,
title: WBSC_PAGE_META.title + ' - Project',
})
</script>
7 changes: 0 additions & 7 deletions pages/report.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,3 @@
<NavButtons />
</div>
</template>

<script setup lang="ts">
usePageMeta({
...WBSC_PAGE_META,
title: WBSC_PAGE_META.title + ' - Report',
})
</script>

0 comments on commit 1aec224

Please # to comment.