mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +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']>()
|
||||
|
||||
nuxtApp._useHead = (meta: MetaObject | ComputedGetter<MetaObject>) => {
|
||||
titleTemplate.value = (unref(meta) as MetaObject).titleTemplate || titleTemplate.value
|
||||
nuxtApp._useHead = (_meta: MetaObject | ComputedGetter<MetaObject>) => {
|
||||
const meta = ref<MetaObject>(_meta)
|
||||
if ('titleTemplate' in meta.value) {
|
||||
titleTemplate.value = meta.value.titleTemplate
|
||||
}
|
||||
|
||||
const headObj = computed(() => {
|
||||
const overrides: MetaObject = { meta: [] }
|
||||
const val = unref(meta) as MetaObject
|
||||
if (titleTemplate.value && 'title' in val) {
|
||||
overrides.title = typeof titleTemplate.value === 'function' ? titleTemplate.value(val.title) : titleTemplate.value.replace(/%s/g, val.title)
|
||||
if (titleTemplate.value && 'title' in meta.value) {
|
||||
overrides.title = typeof titleTemplate.value === 'function' ? titleTemplate.value(meta.value.title) : titleTemplate.value.replace(/%s/g, meta.value.title)
|
||||
}
|
||||
if (val.charset) {
|
||||
overrides.meta!.push({ key: 'charset', charset: val.charset })
|
||||
if (meta.value.charset) {
|
||||
overrides.meta!.push({ key: 'charset', charset: meta.value.charset })
|
||||
}
|
||||
if (val.viewport) {
|
||||
overrides.meta!.push({ name: 'viewport', content: val.viewport })
|
||||
if (meta.value.viewport) {
|
||||
overrides.meta!.push({ name: 'viewport', content: meta.value.viewport })
|
||||
}
|
||||
return defu(overrides, val)
|
||||
return defu(overrides, meta.value)
|
||||
})
|
||||
head.addHeadObjs(headObj as any)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user