elk/composables/setups.ts

52 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 16:26:30 +03:00
import { buildInfo } from 'virtual:build-info'
import type { LocaleObject } from '#i18n'
2022-11-30 03:22:35 +03:00
export function setupPageHeader() {
2023-01-04 16:57:12 +03:00
const { locale, locales, t } = useI18n()
2022-11-30 03:22:35 +03: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,
})
}
}
}
2023-01-04 16:57:12 +03: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 00:13:43 +03:00
htmlAttrs: {
2023-01-04 16:57:12 +03:00
lang: () => locale.value,
dir: () => localeMap[locale.value] ?? 'auto',
2022-11-30 00:13:43 +03:00
},
2023-01-04 16:26:30 +03:00
titleTemplate: (title) => {
let titleTemplate = title ? `${title} | ` : ''
2023-01-04 16:57:12 +03:00
titleTemplate += t('app_name')
2023-01-04 16:26:30 +03:00
if (buildInfo.env !== 'release')
titleTemplate += ` (${buildInfo.env})`
return titleTemplate
},
link,
})
}