refactor: remove useHeadFixed
workaround (#1938)
Co-authored-by: Ayaka Rizumu <464388324@qq.com>
This commit is contained in:
parent
60a37e0bf8
commit
ab2881b9a2
40 changed files with 39 additions and 65 deletions
|
@ -12,7 +12,7 @@ export function setupPageHeader() {
|
|||
return acc
|
||||
}, {} as Record<string, Directions>)
|
||||
|
||||
useHeadFixed({
|
||||
useHead({
|
||||
htmlAttrs: {
|
||||
lang: () => locale.value,
|
||||
dir: () => localeMap[locale.value] ?? 'ltr',
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import type { ComponentInternalInstance } from 'vue'
|
||||
import { onActivated, onDeactivated, ref } from 'vue'
|
||||
import type { ActiveHeadEntry, HeadEntryOptions, UseHeadInput } from '@vueuse/head'
|
||||
import type { SchemaAugmentations } from '@unhead/schema'
|
||||
|
||||
export const isHydrated = ref(false)
|
||||
|
||||
|
@ -36,27 +34,3 @@ export function onReactivated(hook: Function, target?: ComponentInternalInstance
|
|||
}, target)
|
||||
onDeactivated(() => initial.value = false)
|
||||
}
|
||||
|
||||
// TODO: Workaround for Nuxt bug: https://github.com/elk-zone/elk/pull/199#issuecomment-1329771961
|
||||
export function useHeadFixed<T extends SchemaAugmentations>(input: UseHeadInput<T>, options?: HeadEntryOptions): ActiveHeadEntry<UseHeadInput<T>> | void {
|
||||
const deactivated = useDeactivated()
|
||||
if (input && typeof input === 'object' && !('value' in input)) {
|
||||
const title = 'title' in input ? input.title : undefined
|
||||
if (process.server && title) {
|
||||
input.meta = input.meta || []
|
||||
if (Array.isArray(input.meta)) {
|
||||
input.meta.push(
|
||||
{ property: 'og:title', content: (typeof input.title === 'function' ? input.title() : input.title) as string },
|
||||
)
|
||||
}
|
||||
}
|
||||
else if (title) {
|
||||
(input as any).title = () => isHydrated.value ? typeof title === 'function' ? title() : title : ''
|
||||
}
|
||||
}
|
||||
return useHead(() => {
|
||||
if (deactivated.value)
|
||||
return {}
|
||||
return resolveUnref(input)
|
||||
}, options)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue