From ab2881b9a295164e66d03a28ffe51fcf8bf6c4e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20S=C3=A1nchez?= Date: Sat, 1 Apr 2023 13:14:12 +0200 Subject: [PATCH] refactor: remove `useHeadFixed` workaround (#1938) Co-authored-by: Ayaka Rizumu <464388324@qq.com> --- components/status/StatusDetails.vue | 2 +- composables/setups.ts | 2 +- composables/vue.ts | 26 ------------------- .../[[server]]/@[account]/index/followers.vue | 2 +- .../[[server]]/@[account]/index/following.vue | 2 +- pages/[[server]]/@[account]/index/index.vue | 2 +- pages/[[server]]/@[account]/index/media.vue | 2 +- .../@[account]/index/with_replies.vue | 2 +- pages/[[server]]/explore/index.vue | 2 +- pages/[[server]]/explore/links.vue | 2 +- pages/[[server]]/explore/tags.vue | 2 +- pages/[[server]]/explore/users.vue | 2 +- pages/[[server]]/list/[list]/index.vue | 2 +- pages/[[server]]/lists.vue | 2 +- pages/[[server]]/public/index.vue | 2 +- pages/[[server]]/public/local.vue | 2 +- pages/[[server]]/tags/[tag].vue | 2 +- pages/blocks.vue | 2 +- pages/bookmarks.vue | 2 +- pages/compose.vue | 2 +- pages/conversations.vue | 2 +- pages/domain_blocks.vue | 2 +- pages/favourites.vue | 2 +- pages/home.vue | 2 +- pages/mutes.vue | 2 +- pages/notifications/index.vue | 2 +- pages/notifications/mention.vue | 2 +- pages/pinned.vue | 2 +- pages/settings.vue | 2 +- pages/settings/about/index.vue | 2 +- pages/settings/interface/index.vue | 2 +- pages/settings/language/index.vue | 2 +- pages/settings/notifications/index.vue | 2 +- .../settings/notifications/notifications.vue | 2 +- .../notifications/push-notifications.vue | 2 +- pages/settings/preferences/index.vue | 2 +- pages/settings/profile/appearance.vue | 2 +- pages/settings/profile/featured-tags.vue | 2 +- pages/settings/profile/index.vue | 2 +- pages/settings/users/index.vue | 2 +- 40 files changed, 39 insertions(+), 65 deletions(-) diff --git a/components/status/StatusDetails.vue b/components/status/StatusDetails.vue index 77b7bb39..3a0bd148 100644 --- a/components/status/StatusDetails.vue +++ b/components/status/StatusDetails.vue @@ -20,7 +20,7 @@ const createdAt = useFormattedDateTime(status.createdAt) const { t } = useI18n() -useHeadFixed({ +useHead({ title: () => `${getDisplayName(status.account)} ${t('common.in')} ${t('app_name')}: "${removeHTMLTags(status.content) || ''}"`, }) diff --git a/composables/setups.ts b/composables/setups.ts index 736583fd..739f45ad 100644 --- a/composables/setups.ts +++ b/composables/setups.ts @@ -12,7 +12,7 @@ export function setupPageHeader() { return acc }, {} as Record) - useHeadFixed({ + useHead({ htmlAttrs: { lang: () => locale.value, dir: () => localeMap[locale.value] ?? 'ltr', diff --git a/composables/vue.ts b/composables/vue.ts index ebc881ad..9c6cb38d 100644 --- a/composables/vue.ts +++ b/composables/vue.ts @@ -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(input: UseHeadInput, options?: HeadEntryOptions): ActiveHeadEntry> | 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) -} diff --git a/pages/[[server]]/@[account]/index/followers.vue b/pages/[[server]]/@[account]/index/followers.vue index 17bbd0ad..dcb4ebe4 100644 --- a/pages/[[server]]/@[account]/index/followers.vue +++ b/pages/[[server]]/@[account]/index/followers.vue @@ -11,7 +11,7 @@ const paginator = account ? useMastoClient().v1.accounts.listFollowers(account.i const isSelf = useSelfAccount(account) if (account) { - useHeadFixed({ + useHead({ title: () => `${t('account.followers')} | ${getDisplayName(account)} (@${account.acct})`, }) } diff --git a/pages/[[server]]/@[account]/index/following.vue b/pages/[[server]]/@[account]/index/following.vue index f030e281..b65f749d 100644 --- a/pages/[[server]]/@[account]/index/following.vue +++ b/pages/[[server]]/@[account]/index/following.vue @@ -11,7 +11,7 @@ const paginator = account ? useMastoClient().v1.accounts.listFollowing(account.i const isSelf = useSelfAccount(account) if (account) { - useHeadFixed({ + useHead({ title: () => `${t('account.following')} | ${getDisplayName(account)} (@${account.acct})`, }) } diff --git a/pages/[[server]]/@[account]/index/index.vue b/pages/[[server]]/@[account]/index/index.vue index f98bf1ce..e05b07e8 100644 --- a/pages/[[server]]/@[account]/index/index.vue +++ b/pages/[[server]]/@[account]/index/index.vue @@ -17,7 +17,7 @@ function reorderAndFilter(items: mastodon.v1.Status[]) { const paginator = useMastoClient().v1.accounts.listStatuses(account.id, { limit: 30, excludeReplies: true }) if (account) { - useHeadFixed({ + useHead({ title: () => `${t('account.posts')} | ${getDisplayName(account)} (@${account.acct})`, }) } diff --git a/pages/[[server]]/@[account]/index/media.vue b/pages/[[server]]/@[account]/index/media.vue index e31776e7..6db9760a 100644 --- a/pages/[[server]]/@[account]/index/media.vue +++ b/pages/[[server]]/@[account]/index/media.vue @@ -10,7 +10,7 @@ const account = await fetchAccountByHandle(handle) const paginator = useMastoClient().v1.accounts.listStatuses(account.id, { onlyMedia: true, excludeReplies: false }) if (account) { - useHeadFixed({ + useHead({ title: () => `${t('tab.media')} | ${getDisplayName(account)} (@${account.acct})`, }) } diff --git a/pages/[[server]]/@[account]/index/with_replies.vue b/pages/[[server]]/@[account]/index/with_replies.vue index 342d1cc7..b5501c91 100644 --- a/pages/[[server]]/@[account]/index/with_replies.vue +++ b/pages/[[server]]/@[account]/index/with_replies.vue @@ -10,7 +10,7 @@ const account = await fetchAccountByHandle(handle) const paginator = useMastoClient().v1.accounts.listStatuses(account.id, { excludeReplies: false }) if (account) { - useHeadFixed({ + useHead({ title: () => `${t('tab.posts_with_replies')} | ${getDisplayName(account)} (@${account.acct})`, }) } diff --git a/pages/[[server]]/explore/index.vue b/pages/[[server]]/explore/index.vue index a9e10123..df53e0be 100644 --- a/pages/[[server]]/explore/index.vue +++ b/pages/[[server]]/explore/index.vue @@ -7,7 +7,7 @@ const paginator = useMastoClient().v1.trends.listStatuses() const hideNewsTips = useLocalStorage(STORAGE_KEY_HIDE_EXPLORE_POSTS_TIPS, false) -useHeadFixed({ +useHead({ title: () => `${t('tab.posts')} | ${t('nav.explore')}`, }) diff --git a/pages/[[server]]/explore/links.vue b/pages/[[server]]/explore/links.vue index b3025151..92b10309 100644 --- a/pages/[[server]]/explore/links.vue +++ b/pages/[[server]]/explore/links.vue @@ -7,7 +7,7 @@ const paginator = useMastoClient().v1.trends.listLinks() const hideNewsTips = useLocalStorage(STORAGE_KEY_HIDE_EXPLORE_NEWS_TIPS, false) -useHeadFixed({ +useHead({ title: () => `${t('tab.news')} | ${t('nav.explore')}`, }) diff --git a/pages/[[server]]/explore/tags.vue b/pages/[[server]]/explore/tags.vue index a4e6381a..dadbc5ed 100644 --- a/pages/[[server]]/explore/tags.vue +++ b/pages/[[server]]/explore/tags.vue @@ -10,7 +10,7 @@ const paginator = client.v1.trends.listTags({ const hideTagsTips = useLocalStorage(STORAGE_KEY_HIDE_EXPLORE_TAGS_TIPS, false) -useHeadFixed({ +useHead({ title: () => `${t('tab.hashtags')} | ${t('nav.explore')}`, }) diff --git a/pages/[[server]]/explore/users.vue b/pages/[[server]]/explore/users.vue index 96e656ec..b3080094 100644 --- a/pages/[[server]]/explore/users.vue +++ b/pages/[[server]]/explore/users.vue @@ -4,7 +4,7 @@ const { t } = useI18n() // limit: 20 is the default configuration of the official client const paginator = useMastoClient().v2.suggestions.list({ limit: 20 }) -useHeadFixed({ +useHead({ title: () => `${t('tab.for_you')} | ${t('nav.explore')}`, }) diff --git a/pages/[[server]]/list/[list]/index.vue b/pages/[[server]]/list/[list]/index.vue index bdee17b9..1780ebcf 100644 --- a/pages/[[server]]/list/[list]/index.vue +++ b/pages/[[server]]/list/[list]/index.vue @@ -35,7 +35,7 @@ const { client } = $(useMasto()) const { data: listInfo, refresh } = $(await useAsyncData(() => client.v1.lists.fetch(list), { default: () => shallowRef() })) if (listInfo) { - useHeadFixed({ + useHead({ title: () => `${listInfo.title} | ${route.fullPath.endsWith('/accounts') ? t('tab.accounts') : t('tab.posts')} | ${t('nav.lists')}`, }) } diff --git a/pages/[[server]]/lists.vue b/pages/[[server]]/lists.vue index 2859f267..e7bf9153 100644 --- a/pages/[[server]]/lists.vue +++ b/pages/[[server]]/lists.vue @@ -11,7 +11,7 @@ const client = useMastoClient() const paginator = client.v1.lists.list() -useHeadFixed({ +useHead({ title: () => t('nav.lists'), }) diff --git a/pages/[[server]]/public/index.vue b/pages/[[server]]/public/index.vue index 67c3ab78..e1fb4a21 100644 --- a/pages/[[server]]/public/index.vue +++ b/pages/[[server]]/public/index.vue @@ -3,7 +3,7 @@ const { t } = useI18n() -useHeadFixed({ +useHead({ title: () => t('title.federated_timeline'), }) diff --git a/pages/[[server]]/public/local.vue b/pages/[[server]]/public/local.vue index 70bda8a1..18e80bec 100644 --- a/pages/[[server]]/public/local.vue +++ b/pages/[[server]]/public/local.vue @@ -2,7 +2,7 @@ const { t } = useI18n() -useHeadFixed({ +useHead({ title: () => t('title.local_timeline'), }) diff --git a/pages/[[server]]/tags/[tag].vue b/pages/[[server]]/tags/[tag].vue index 3df97c80..847ae7f5 100644 --- a/pages/[[server]]/tags/[tag].vue +++ b/pages/[[server]]/tags/[tag].vue @@ -13,7 +13,7 @@ const paginator = client.v1.timelines.listHashtag(tagName) const stream = useStreaming(client => client.v1.stream.streamTagTimeline(tagName)) if (tag) { - useHeadFixed({ + useHead({ title: () => `#${tag.name}`, }) } diff --git a/pages/blocks.vue b/pages/blocks.vue index 9fd63656..4e3b6015 100644 --- a/pages/blocks.vue +++ b/pages/blocks.vue @@ -5,7 +5,7 @@ definePageMeta({ const { t } = useI18n() -useHeadFixed({ +useHead({ title: () => t('nav.blocked_users'), }) diff --git a/pages/bookmarks.vue b/pages/bookmarks.vue index 18b424ee..1d0ed886 100644 --- a/pages/bookmarks.vue +++ b/pages/bookmarks.vue @@ -5,7 +5,7 @@ definePageMeta({ const { t } = useI18n() -useHeadFixed({ +useHead({ title: () => t('nav.bookmarks'), }) diff --git a/pages/compose.vue b/pages/compose.vue index 9709cbc7..656ca1fc 100644 --- a/pages/compose.vue +++ b/pages/compose.vue @@ -1,6 +1,6 @@ diff --git a/pages/conversations.vue b/pages/conversations.vue index fe54fbec..5c17537b 100644 --- a/pages/conversations.vue +++ b/pages/conversations.vue @@ -5,7 +5,7 @@ definePageMeta({ const { t } = useI18n() -useHeadFixed({ +useHead({ title: () => t('nav.conversations'), }) diff --git a/pages/domain_blocks.vue b/pages/domain_blocks.vue index f2f84fb5..663292b6 100644 --- a/pages/domain_blocks.vue +++ b/pages/domain_blocks.vue @@ -5,7 +5,7 @@ definePageMeta({ const { t } = useI18n() -useHeadFixed({ +useHead({ title: () => t('nav.blocked_domains'), }) diff --git a/pages/favourites.vue b/pages/favourites.vue index 2d107785..7f840e4b 100644 --- a/pages/favourites.vue +++ b/pages/favourites.vue @@ -5,7 +5,7 @@ definePageMeta({ const { t } = useI18n() -useHeadFixed({ +useHead({ title: () => t('nav.favourites'), }) diff --git a/pages/home.vue b/pages/home.vue index 90b97bbe..3bbf29fb 100644 --- a/pages/home.vue +++ b/pages/home.vue @@ -12,7 +12,7 @@ if (process.client && route.path === '/signin/callback') router.push('/home') const { t } = useI18n() -useHeadFixed({ +useHead({ title: () => t('nav.home'), }) diff --git a/pages/mutes.vue b/pages/mutes.vue index 92db7eac..c1e0bda9 100644 --- a/pages/mutes.vue +++ b/pages/mutes.vue @@ -5,7 +5,7 @@ definePageMeta({ const { t } = useI18n() -useHeadFixed({ +useHead({ title: () => t('nav.muted_users'), }) diff --git a/pages/notifications/index.vue b/pages/notifications/index.vue index 5862ee7c..e9873b95 100644 --- a/pages/notifications/index.vue +++ b/pages/notifications/index.vue @@ -1,6 +1,6 @@ diff --git a/pages/notifications/mention.vue b/pages/notifications/mention.vue index c157d6f8..8a584914 100644 --- a/pages/notifications/mention.vue +++ b/pages/notifications/mention.vue @@ -1,6 +1,6 @@ diff --git a/pages/pinned.vue b/pages/pinned.vue index 7273385f..f573c10f 100644 --- a/pages/pinned.vue +++ b/pages/pinned.vue @@ -5,7 +5,7 @@ definePageMeta({ const { t } = useI18n() -useHeadFixed({ +useHead({ title: () => t('account.pinned'), }) diff --git a/pages/settings.vue b/pages/settings.vue index f2c8e614..38c81872 100644 --- a/pages/settings.vue +++ b/pages/settings.vue @@ -5,7 +5,7 @@ definePageMeta({ const { t } = useI18n() -useHeadFixed({ +useHead({ title: () => t('nav.settings'), }) diff --git a/pages/settings/about/index.vue b/pages/settings/about/index.vue index 215efc1a..03b19e10 100644 --- a/pages/settings/about/index.vue +++ b/pages/settings/about/index.vue @@ -2,7 +2,7 @@ const buildInfo = useBuildInfo() const { t } = useI18n() -useHeadFixed({ +useHead({ title: () => `${t('settings.about.label')} | ${t('nav.settings')}`, }) diff --git a/pages/settings/interface/index.vue b/pages/settings/interface/index.vue index 804e7f89..2ac20970 100644 --- a/pages/settings/interface/index.vue +++ b/pages/settings/interface/index.vue @@ -1,7 +1,7 @@ diff --git a/pages/settings/language/index.vue b/pages/settings/language/index.vue index 9a8e3042..5f16bb11 100644 --- a/pages/settings/language/index.vue +++ b/pages/settings/language/index.vue @@ -5,7 +5,7 @@ const { t, locale } = useI18n() const translationStatus: ElkTranslationStatus = await import('~/elk-translation-status.json').then(m => m.default) -useHeadFixed({ +useHead({ title: () => `${t('settings.language.label')} | ${t('nav.settings')}`, }) const status = computed(() => { diff --git a/pages/settings/notifications/index.vue b/pages/settings/notifications/index.vue index ef95d85a..80704319 100644 --- a/pages/settings/notifications/index.vue +++ b/pages/settings/notifications/index.vue @@ -6,7 +6,7 @@ definePageMeta({ const { t } = useI18n() const pwaEnabled = useAppConfig().pwaEnabled -useHeadFixed({ +useHead({ title: () => `${t('settings.notifications.label')} | ${t('nav.settings')}`, }) diff --git a/pages/settings/notifications/notifications.vue b/pages/settings/notifications/notifications.vue index 68ede7fc..e58ee448 100644 --- a/pages/settings/notifications/notifications.vue +++ b/pages/settings/notifications/notifications.vue @@ -5,7 +5,7 @@ definePageMeta({ const { t } = useI18n() -useHeadFixed({ +useHead({ title: () => `${t('settings.notifications.notifications.label')} | ${t('settings.notifications.label')} | ${t('nav.settings')}`, }) diff --git a/pages/settings/notifications/push-notifications.vue b/pages/settings/notifications/push-notifications.vue index 641cb5a0..5bf238cb 100644 --- a/pages/settings/notifications/push-notifications.vue +++ b/pages/settings/notifications/push-notifications.vue @@ -8,7 +8,7 @@ definePageMeta({ const { t } = useI18n() -useHeadFixed({ +useHead({ title: () => `${t('settings.notifications.push_notifications.label')} | ${t('settings.notifications.label')} | ${t('nav.settings')}`, }) diff --git a/pages/settings/preferences/index.vue b/pages/settings/preferences/index.vue index f20819c6..c3344105 100644 --- a/pages/settings/preferences/index.vue +++ b/pages/settings/preferences/index.vue @@ -1,7 +1,7 @@ diff --git a/pages/settings/profile/index.vue b/pages/settings/profile/index.vue index 35290952..c480767a 100644 --- a/pages/settings/profile/index.vue +++ b/pages/settings/profile/index.vue @@ -5,7 +5,7 @@ definePageMeta({ const { t } = useI18n() -useHeadFixed({ +useHead({ title: () => `${t('settings.profile.label')} | ${t('nav.settings')}`, }) diff --git a/pages/settings/users/index.vue b/pages/settings/users/index.vue index 7d667b9d..82734a09 100644 --- a/pages/settings/users/index.vue +++ b/pages/settings/users/index.vue @@ -5,7 +5,7 @@ import type { UserLogin } from '~/types' const { t } = useI18n() -useHeadFixed({ +useHead({ title: () => `${t('settings.users.label')} | ${t('nav.settings')}`, })