feat: i18n PWA webmanifests (#805)

Co-authored-by: Daniel Roe <daniel@roe.dev>
This commit is contained in:
Joaquín Sánchez 2023-01-06 13:48:43 +01:00 committed by GitHub
parent 18056038c7
commit 85ac005570
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 190 additions and 73 deletions

View file

@ -1,5 +1,3 @@
import { pwaInfo } from 'virtual:pwa-info'
import type { Link } from '@unhead/schema'
import type { Directions } from 'vue-i18n-routing'
import { buildInfo } from 'virtual:build-info'
import type { LocaleObject } from '#i18n'
@ -7,28 +5,6 @@ import type { LocaleObject } from '#i18n'
export function setupPageHeader() {
const { locale, locales, t } = useI18n()
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 = (locales.value as LocaleObject[]).reduce((acc, l) => {
acc[l.code!] = l.dir ?? 'auto'
return acc
@ -46,6 +22,12 @@ export function setupPageHeader() {
titleTemplate += ` (${buildInfo.env})`
return titleTemplate
},
link,
link: process.client && useRuntimeConfig().public.pwaEnabled
? () => [{
key: 'webmanifest',
rel: 'manifest',
href: `/manifest-${locale.value}.webmanifest`,
}]
: [],
})
}