refactor: remove `useHeadFixed` workaround (#1938)

Co-authored-by: Ayaka Rizumu <464388324@qq.com>
zio/stable
Joaquín Sánchez 2023-04-01 13:14:12 +02:00 committed by GitHub
parent 60a37e0bf8
commit ab2881b9a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
40 changed files with 39 additions and 65 deletions

View File

@ -20,7 +20,7 @@ const createdAt = useFormattedDateTime(status.createdAt)
const { t } = useI18n() const { t } = useI18n()
useHeadFixed({ useHead({
title: () => `${getDisplayName(status.account)} ${t('common.in')} ${t('app_name')}: "${removeHTMLTags(status.content) || ''}"`, title: () => `${getDisplayName(status.account)} ${t('common.in')} ${t('app_name')}: "${removeHTMLTags(status.content) || ''}"`,
}) })
</script> </script>

View File

@ -12,7 +12,7 @@ export function setupPageHeader() {
return acc return acc
}, {} as Record<string, Directions>) }, {} as Record<string, Directions>)
useHeadFixed({ useHead({
htmlAttrs: { htmlAttrs: {
lang: () => locale.value, lang: () => locale.value,
dir: () => localeMap[locale.value] ?? 'ltr', dir: () => localeMap[locale.value] ?? 'ltr',

View File

@ -1,7 +1,5 @@
import type { ComponentInternalInstance } from 'vue' import type { ComponentInternalInstance } from 'vue'
import { onActivated, onDeactivated, ref } 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) export const isHydrated = ref(false)
@ -36,27 +34,3 @@ export function onReactivated(hook: Function, target?: ComponentInternalInstance
}, target) }, target)
onDeactivated(() => initial.value = false) 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)
}

View File

@ -11,7 +11,7 @@ const paginator = account ? useMastoClient().v1.accounts.listFollowers(account.i
const isSelf = useSelfAccount(account) const isSelf = useSelfAccount(account)
if (account) { if (account) {
useHeadFixed({ useHead({
title: () => `${t('account.followers')} | ${getDisplayName(account)} (@${account.acct})`, title: () => `${t('account.followers')} | ${getDisplayName(account)} (@${account.acct})`,
}) })
} }

View File

@ -11,7 +11,7 @@ const paginator = account ? useMastoClient().v1.accounts.listFollowing(account.i
const isSelf = useSelfAccount(account) const isSelf = useSelfAccount(account)
if (account) { if (account) {
useHeadFixed({ useHead({
title: () => `${t('account.following')} | ${getDisplayName(account)} (@${account.acct})`, title: () => `${t('account.following')} | ${getDisplayName(account)} (@${account.acct})`,
}) })
} }

View File

@ -17,7 +17,7 @@ function reorderAndFilter(items: mastodon.v1.Status[]) {
const paginator = useMastoClient().v1.accounts.listStatuses(account.id, { limit: 30, excludeReplies: true }) const paginator = useMastoClient().v1.accounts.listStatuses(account.id, { limit: 30, excludeReplies: true })
if (account) { if (account) {
useHeadFixed({ useHead({
title: () => `${t('account.posts')} | ${getDisplayName(account)} (@${account.acct})`, title: () => `${t('account.posts')} | ${getDisplayName(account)} (@${account.acct})`,
}) })
} }

View File

@ -10,7 +10,7 @@ const account = await fetchAccountByHandle(handle)
const paginator = useMastoClient().v1.accounts.listStatuses(account.id, { onlyMedia: true, excludeReplies: false }) const paginator = useMastoClient().v1.accounts.listStatuses(account.id, { onlyMedia: true, excludeReplies: false })
if (account) { if (account) {
useHeadFixed({ useHead({
title: () => `${t('tab.media')} | ${getDisplayName(account)} (@${account.acct})`, title: () => `${t('tab.media')} | ${getDisplayName(account)} (@${account.acct})`,
}) })
} }

View File

@ -10,7 +10,7 @@ const account = await fetchAccountByHandle(handle)
const paginator = useMastoClient().v1.accounts.listStatuses(account.id, { excludeReplies: false }) const paginator = useMastoClient().v1.accounts.listStatuses(account.id, { excludeReplies: false })
if (account) { if (account) {
useHeadFixed({ useHead({
title: () => `${t('tab.posts_with_replies')} | ${getDisplayName(account)} (@${account.acct})`, title: () => `${t('tab.posts_with_replies')} | ${getDisplayName(account)} (@${account.acct})`,
}) })
} }

View File

@ -7,7 +7,7 @@ const paginator = useMastoClient().v1.trends.listStatuses()
const hideNewsTips = useLocalStorage(STORAGE_KEY_HIDE_EXPLORE_POSTS_TIPS, false) const hideNewsTips = useLocalStorage(STORAGE_KEY_HIDE_EXPLORE_POSTS_TIPS, false)
useHeadFixed({ useHead({
title: () => `${t('tab.posts')} | ${t('nav.explore')}`, title: () => `${t('tab.posts')} | ${t('nav.explore')}`,
}) })
</script> </script>

View File

@ -7,7 +7,7 @@ const paginator = useMastoClient().v1.trends.listLinks()
const hideNewsTips = useLocalStorage(STORAGE_KEY_HIDE_EXPLORE_NEWS_TIPS, false) const hideNewsTips = useLocalStorage(STORAGE_KEY_HIDE_EXPLORE_NEWS_TIPS, false)
useHeadFixed({ useHead({
title: () => `${t('tab.news')} | ${t('nav.explore')}`, title: () => `${t('tab.news')} | ${t('nav.explore')}`,
}) })
</script> </script>

View File

@ -10,7 +10,7 @@ const paginator = client.v1.trends.listTags({
const hideTagsTips = useLocalStorage(STORAGE_KEY_HIDE_EXPLORE_TAGS_TIPS, false) const hideTagsTips = useLocalStorage(STORAGE_KEY_HIDE_EXPLORE_TAGS_TIPS, false)
useHeadFixed({ useHead({
title: () => `${t('tab.hashtags')} | ${t('nav.explore')}`, title: () => `${t('tab.hashtags')} | ${t('nav.explore')}`,
}) })
</script> </script>

View File

@ -4,7 +4,7 @@ const { t } = useI18n()
// limit: 20 is the default configuration of the official client // limit: 20 is the default configuration of the official client
const paginator = useMastoClient().v2.suggestions.list({ limit: 20 }) const paginator = useMastoClient().v2.suggestions.list({ limit: 20 })
useHeadFixed({ useHead({
title: () => `${t('tab.for_you')} | ${t('nav.explore')}`, title: () => `${t('tab.for_you')} | ${t('nav.explore')}`,
}) })
</script> </script>

View File

@ -35,7 +35,7 @@ const { client } = $(useMasto())
const { data: listInfo, refresh } = $(await useAsyncData(() => client.v1.lists.fetch(list), { default: () => shallowRef() })) const { data: listInfo, refresh } = $(await useAsyncData(() => client.v1.lists.fetch(list), { default: () => shallowRef() }))
if (listInfo) { if (listInfo) {
useHeadFixed({ useHead({
title: () => `${listInfo.title} | ${route.fullPath.endsWith('/accounts') ? t('tab.accounts') : t('tab.posts')} | ${t('nav.lists')}`, title: () => `${listInfo.title} | ${route.fullPath.endsWith('/accounts') ? t('tab.accounts') : t('tab.posts')} | ${t('nav.lists')}`,
}) })
} }

View File

@ -11,7 +11,7 @@ const client = useMastoClient()
const paginator = client.v1.lists.list() const paginator = client.v1.lists.list()
useHeadFixed({ useHead({
title: () => t('nav.lists'), title: () => t('nav.lists'),
}) })

View File

@ -3,7 +3,7 @@
const { t } = useI18n() const { t } = useI18n()
useHeadFixed({ useHead({
title: () => t('title.federated_timeline'), title: () => t('title.federated_timeline'),
}) })
</script> </script>

View File

@ -2,7 +2,7 @@
const { t } = useI18n() const { t } = useI18n()
useHeadFixed({ useHead({
title: () => t('title.local_timeline'), title: () => t('title.local_timeline'),
}) })
</script> </script>

View File

@ -13,7 +13,7 @@ const paginator = client.v1.timelines.listHashtag(tagName)
const stream = useStreaming(client => client.v1.stream.streamTagTimeline(tagName)) const stream = useStreaming(client => client.v1.stream.streamTagTimeline(tagName))
if (tag) { if (tag) {
useHeadFixed({ useHead({
title: () => `#${tag.name}`, title: () => `#${tag.name}`,
}) })
} }

View File

@ -5,7 +5,7 @@ definePageMeta({
const { t } = useI18n() const { t } = useI18n()
useHeadFixed({ useHead({
title: () => t('nav.blocked_users'), title: () => t('nav.blocked_users'),
}) })
</script> </script>

View File

@ -5,7 +5,7 @@ definePageMeta({
const { t } = useI18n() const { t } = useI18n()
useHeadFixed({ useHead({
title: () => t('nav.bookmarks'), title: () => t('nav.bookmarks'),
}) })
</script> </script>

View File

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
const { t } = useI18n() const { t } = useI18n()
useHeadFixed({ useHead({
title: () => t('nav.compose'), title: () => t('nav.compose'),
}) })
</script> </script>

View File

@ -5,7 +5,7 @@ definePageMeta({
const { t } = useI18n() const { t } = useI18n()
useHeadFixed({ useHead({
title: () => t('nav.conversations'), title: () => t('nav.conversations'),
}) })
</script> </script>

View File

@ -5,7 +5,7 @@ definePageMeta({
const { t } = useI18n() const { t } = useI18n()
useHeadFixed({ useHead({
title: () => t('nav.blocked_domains'), title: () => t('nav.blocked_domains'),
}) })
</script> </script>

View File

@ -5,7 +5,7 @@ definePageMeta({
const { t } = useI18n() const { t } = useI18n()
useHeadFixed({ useHead({
title: () => t('nav.favourites'), title: () => t('nav.favourites'),
}) })
</script> </script>

View File

@ -12,7 +12,7 @@ if (process.client && route.path === '/signin/callback')
router.push('/home') router.push('/home')
const { t } = useI18n() const { t } = useI18n()
useHeadFixed({ useHead({
title: () => t('nav.home'), title: () => t('nav.home'),
}) })
</script> </script>

View File

@ -5,7 +5,7 @@ definePageMeta({
const { t } = useI18n() const { t } = useI18n()
useHeadFixed({ useHead({
title: () => t('nav.muted_users'), title: () => t('nav.muted_users'),
}) })
</script> </script>

View File

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
const { t } = useI18n() const { t } = useI18n()
useHeadFixed({ useHead({
title: () => `${t('tab.notifications_all')} | ${t('nav.notifications')}`, title: () => `${t('tab.notifications_all')} | ${t('nav.notifications')}`,
}) })
</script> </script>

View File

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
const { t } = useI18n() const { t } = useI18n()
useHeadFixed({ useHead({
title: () => `${t('tab.notifications_mention')} | ${t('nav.notifications')}`, title: () => `${t('tab.notifications_mention')} | ${t('nav.notifications')}`,
}) })
</script> </script>

View File

@ -5,7 +5,7 @@ definePageMeta({
const { t } = useI18n() const { t } = useI18n()
useHeadFixed({ useHead({
title: () => t('account.pinned'), title: () => t('account.pinned'),
}) })
</script> </script>

View File

@ -5,7 +5,7 @@ definePageMeta({
const { t } = useI18n() const { t } = useI18n()
useHeadFixed({ useHead({
title: () => t('nav.settings'), title: () => t('nav.settings'),
}) })

View File

@ -2,7 +2,7 @@
const buildInfo = useBuildInfo() const buildInfo = useBuildInfo()
const { t } = useI18n() const { t } = useI18n()
useHeadFixed({ useHead({
title: () => `${t('settings.about.label')} | ${t('nav.settings')}`, title: () => `${t('settings.about.label')} | ${t('nav.settings')}`,
}) })

View File

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
const { t } = useI18n() const { t } = useI18n()
useHeadFixed({ useHead({
title: () => `${t('settings.interface.label')} | ${t('nav.settings')}`, title: () => `${t('settings.interface.label')} | ${t('nav.settings')}`,
}) })
</script> </script>

View File

@ -5,7 +5,7 @@ const { t, locale } = useI18n()
const translationStatus: ElkTranslationStatus = await import('~/elk-translation-status.json').then(m => m.default) const translationStatus: ElkTranslationStatus = await import('~/elk-translation-status.json').then(m => m.default)
useHeadFixed({ useHead({
title: () => `${t('settings.language.label')} | ${t('nav.settings')}`, title: () => `${t('settings.language.label')} | ${t('nav.settings')}`,
}) })
const status = computed(() => { const status = computed(() => {

View File

@ -6,7 +6,7 @@ definePageMeta({
const { t } = useI18n() const { t } = useI18n()
const pwaEnabled = useAppConfig().pwaEnabled const pwaEnabled = useAppConfig().pwaEnabled
useHeadFixed({ useHead({
title: () => `${t('settings.notifications.label')} | ${t('nav.settings')}`, title: () => `${t('settings.notifications.label')} | ${t('nav.settings')}`,
}) })
</script> </script>

View File

@ -5,7 +5,7 @@ definePageMeta({
const { t } = useI18n() const { t } = useI18n()
useHeadFixed({ useHead({
title: () => `${t('settings.notifications.notifications.label')} | ${t('settings.notifications.label')} | ${t('nav.settings')}`, title: () => `${t('settings.notifications.notifications.label')} | ${t('settings.notifications.label')} | ${t('nav.settings')}`,
}) })
</script> </script>

View File

@ -8,7 +8,7 @@ definePageMeta({
const { t } = useI18n() const { t } = useI18n()
useHeadFixed({ useHead({
title: () => `${t('settings.notifications.push_notifications.label')} | ${t('settings.notifications.label')} | ${t('nav.settings')}`, title: () => `${t('settings.notifications.push_notifications.label')} | ${t('settings.notifications.label')} | ${t('nav.settings')}`,
}) })
</script> </script>

View File

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
const { t } = useI18n() const { t } = useI18n()
useHeadFixed({ useHead({
title: () => `${t('settings.preferences.label')} | ${t('nav.settings')}`, title: () => `${t('settings.preferences.label')} | ${t('nav.settings')}`,
}) })

View File

@ -9,7 +9,7 @@ definePageMeta({
const { t } = useI18n() const { t } = useI18n()
useHeadFixed({ useHead({
title: () => `${t('settings.profile.appearance.title')} | ${t('nav.settings')}`, title: () => `${t('settings.profile.appearance.title')} | ${t('nav.settings')}`,
}) })

View File

@ -5,7 +5,7 @@ definePageMeta({
const { t } = useI18n() const { t } = useI18n()
useHeadFixed({ useHead({
title: () => `${t('settings.profile.featured_tags.label')} | ${t('nav.settings')}`, title: () => `${t('settings.profile.featured_tags.label')} | ${t('nav.settings')}`,
}) })
</script> </script>

View File

@ -5,7 +5,7 @@ definePageMeta({
const { t } = useI18n() const { t } = useI18n()
useHeadFixed({ useHead({
title: () => `${t('settings.profile.label')} | ${t('nav.settings')}`, title: () => `${t('settings.profile.label')} | ${t('nav.settings')}`,
}) })
</script> </script>

View File

@ -5,7 +5,7 @@ import type { UserLogin } from '~/types'
const { t } = useI18n() const { t } = useI18n()
useHeadFixed({ useHead({
title: () => `${t('settings.users.label')} | ${t('nav.settings')}`, title: () => `${t('settings.users.label')} | ${t('nav.settings')}`,
}) })