2022-12-26 15:12:04 +00:00
|
|
|
import type { Directions } from 'vue-i18n-routing'
|
|
|
|
import type { LocaleObject } from '#i18n'
|
2022-11-28 09:01:14 +00:00
|
|
|
|
2022-11-30 00:22:35 +00:00
|
|
|
export function setupPageHeader() {
|
2023-01-04 13:57:12 +00:00
|
|
|
const { locale, locales, t } = useI18n()
|
2023-01-10 20:35:34 +00:00
|
|
|
const colorMode = useColorMode()
|
2023-01-08 11:17:09 +00:00
|
|
|
const buildInfo = useBuildInfo()
|
2022-11-30 00:22:35 +00:00
|
|
|
|
2023-01-04 13:57:12 +00:00
|
|
|
const localeMap = (locales.value as LocaleObject[]).reduce((acc, l) => {
|
2022-12-27 21:04:52 +00:00
|
|
|
acc[l.code!] = l.dir ?? 'auto'
|
2022-12-26 15:12:04 +00:00
|
|
|
return acc
|
|
|
|
}, {} as Record<string, Directions>)
|
|
|
|
|
2022-11-29 22:49:25 +00:00
|
|
|
useHeadFixed({
|
2022-11-29 21:13:43 +00:00
|
|
|
htmlAttrs: {
|
2023-01-04 13:57:12 +00:00
|
|
|
lang: () => locale.value,
|
|
|
|
dir: () => localeMap[locale.value] ?? 'auto',
|
2022-11-29 21:13:43 +00:00
|
|
|
},
|
2023-01-04 13:26:30 +00:00
|
|
|
titleTemplate: (title) => {
|
|
|
|
let titleTemplate = title ? `${title} | ` : ''
|
2023-01-04 13:57:12 +00:00
|
|
|
titleTemplate += t('app_name')
|
2023-01-04 13:26:30 +00:00
|
|
|
if (buildInfo.env !== 'release')
|
|
|
|
titleTemplate += ` (${buildInfo.env})`
|
|
|
|
return titleTemplate
|
|
|
|
},
|
2023-01-06 12:48:43 +00:00
|
|
|
link: process.client && useRuntimeConfig().public.pwaEnabled
|
|
|
|
? () => [{
|
|
|
|
key: 'webmanifest',
|
|
|
|
rel: 'manifest',
|
2023-01-10 20:35:34 +00:00
|
|
|
href: `/manifest-${locale.value}${colorMode.value === 'dark' ? '-dark' : ''}.webmanifest`,
|
2023-01-06 12:48:43 +00:00
|
|
|
}]
|
|
|
|
: [],
|
2022-11-28 09:01:14 +00:00
|
|
|
})
|
|
|
|
}
|