elk/composables/setups.ts

53 lines
1.3 KiB
TypeScript
Raw Normal View History

import { pwaInfo } from 'virtual:pwa-info'
import type { Link } from '@unhead/schema'
import type { Directions } from 'vue-i18n-routing'
2023-01-04 13:26:30 +00:00
import { buildInfo } from 'virtual:build-info'
2022-12-28 03:50:29 +00:00
import { APP_NAME } from '~/constants'
import type { LocaleObject } from '#i18n'
2022-11-30 00:22:35 +00:00
export function setupPageHeader() {
2022-11-29 21:13:43 +00:00
const i18n = useI18n()
2022-11-30 00:22:35 +00:00
const link: Link[] = []
if (pwaInfo && pwaInfo.webManifest) {
const { webManifest } = pwaInfo
if (webManifest) {
const { href, useCredentials } = webManifest
if (useCredentials) {
link.push({
rel: 'manifest',
href,
crossorigin: 'use-credentials',
})
}
else {
link.push({
rel: 'manifest',
href,
})
}
}
}
const localeMap = (i18n.locales.value as LocaleObject[]).reduce((acc, l) => {
acc[l.code!] = l.dir ?? 'auto'
return acc
}, {} as Record<string, Directions>)
useHeadFixed({
2022-11-29 21:13:43 +00:00
htmlAttrs: {
lang: () => i18n.locale.value,
dir: () => localeMap[i18n.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} | ` : ''
titleTemplate += APP_NAME
if (buildInfo.env !== 'release')
titleTemplate += ` (${buildInfo.env})`
return titleTemplate
},
link,
})
}