1
0
mirror of https://github.com/elk-zone/elk synced 2024-11-27 22:38:11 +09:00
elk/composables/setups.ts

34 lines
967 B
TypeScript
Raw Normal View History

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