mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 23:22:02 +00:00
fix(nuxt3): re-enable computed metadata in useHead (#4260)
This commit is contained in:
parent
b142666561
commit
38cd6f0f03
@ -17,22 +17,24 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|||||||
|
|
||||||
const titleTemplate = ref<MetaObject['titleTemplate']>()
|
const titleTemplate = ref<MetaObject['titleTemplate']>()
|
||||||
|
|
||||||
nuxtApp._useHead = (meta: MetaObject | ComputedGetter<MetaObject>) => {
|
nuxtApp._useHead = (_meta: MetaObject | ComputedGetter<MetaObject>) => {
|
||||||
titleTemplate.value = (unref(meta) as MetaObject).titleTemplate || titleTemplate.value
|
const meta = ref<MetaObject>(_meta)
|
||||||
|
if ('titleTemplate' in meta.value) {
|
||||||
|
titleTemplate.value = meta.value.titleTemplate
|
||||||
|
}
|
||||||
|
|
||||||
const headObj = computed(() => {
|
const headObj = computed(() => {
|
||||||
const overrides: MetaObject = { meta: [] }
|
const overrides: MetaObject = { meta: [] }
|
||||||
const val = unref(meta) as MetaObject
|
if (titleTemplate.value && 'title' in meta.value) {
|
||||||
if (titleTemplate.value && 'title' in val) {
|
overrides.title = typeof titleTemplate.value === 'function' ? titleTemplate.value(meta.value.title) : titleTemplate.value.replace(/%s/g, meta.value.title)
|
||||||
overrides.title = typeof titleTemplate.value === 'function' ? titleTemplate.value(val.title) : titleTemplate.value.replace(/%s/g, val.title)
|
|
||||||
}
|
}
|
||||||
if (val.charset) {
|
if (meta.value.charset) {
|
||||||
overrides.meta!.push({ key: 'charset', charset: val.charset })
|
overrides.meta!.push({ key: 'charset', charset: meta.value.charset })
|
||||||
}
|
}
|
||||||
if (val.viewport) {
|
if (meta.value.viewport) {
|
||||||
overrides.meta!.push({ name: 'viewport', content: val.viewport })
|
overrides.meta!.push({ name: 'viewport', content: meta.value.viewport })
|
||||||
}
|
}
|
||||||
return defu(overrides, val)
|
return defu(overrides, meta.value)
|
||||||
})
|
})
|
||||||
head.addHeadObjs(headObj as any)
|
head.addHeadObjs(headObj as any)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user