2022-12-18 00:29:16 +01:00
|
|
|
import { pwaInfo } from 'virtual:pwa-info'
|
|
|
|
import type { Link } from '@unhead/schema'
|
2022-12-26 16:12:04 +01:00
|
|
|
import type { Directions } from 'vue-i18n-routing'
|
2023-01-04 14:26:30 +01:00
|
|
|
import { buildInfo } from 'virtual:build-info'
|
2022-12-28 04:50:29 +01:00
|
|
|
import { APP_NAME } from '~/constants'
|
2022-12-26 16:12:04 +01:00
|
|
|
import type { LocaleObject } from '#i18n'
|
2022-11-28 10:01:14 +01:00
|
|
|
|
2022-11-30 01:22:35 +01:00
|
|
|
export function setupPageHeader() {
|
2022-11-29 22:13:43 +01:00
|
|
|
const i18n = useI18n()
|
2022-11-30 01:22:35 +01:00
|
|
|
|
2022-12-18 00:29:16 +01: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,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-26 16:12:04 +01:00
|
|
|
const localeMap = (i18n.locales.value as LocaleObject[]).reduce((acc, l) => {
|
2022-12-27 22:04:52 +01:00
|
|
|
acc[l.code!] = l.dir ?? 'auto'
|
2022-12-26 16:12:04 +01:00
|
|
|
return acc
|
|
|
|
}, {} as Record<string, Directions>)
|
|
|
|
|
2022-11-29 23:49:25 +01:00
|
|
|
useHeadFixed({
|
2022-11-29 22:13:43 +01:00
|
|
|
htmlAttrs: {
|
|
|
|
lang: () => i18n.locale.value,
|
2022-12-27 22:04:52 +01:00
|
|
|
dir: () => localeMap[i18n.locale.value] ?? 'auto',
|
2022-11-29 22:13:43 +01:00
|
|
|
},
|
2023-01-04 14:26:30 +01:00
|
|
|
titleTemplate: (title) => {
|
|
|
|
let titleTemplate = title ? `${title} | ` : ''
|
|
|
|
titleTemplate += APP_NAME
|
|
|
|
if (buildInfo.env !== 'release')
|
|
|
|
titleTemplate += ` (${buildInfo.env})`
|
|
|
|
return titleTemplate
|
|
|
|
},
|
2022-12-18 00:29:16 +01:00
|
|
|
link,
|
2022-11-28 10:01:14 +01:00
|
|
|
})
|
|
|
|
}
|