chore: remove useHeadFixed workaround

This commit is contained in:
userquin 2023-02-17 23:20:50 +01:00
parent 76efc724eb
commit 1cb2069f64
42 changed files with 1216 additions and 227 deletions

View file

@ -22,7 +22,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) || ''}"`,
}) })

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,8 +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 { HeadAugmentations } from '@nuxt/schema'
import { useHead } from '#head'
export const isHydrated = ref(false) export const isHydrated = ref(false)
@ -37,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 HeadAugmentations>(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

@ -107,7 +107,7 @@
}, },
"devDependencies": { "devDependencies": {
"@antfu/eslint-config": "^0.34.1", "@antfu/eslint-config": "^0.34.1",
"@antfu/ni": "^0.19.0", "@antfu/ni": "^0.20.0",
"@types/chroma-js": "^2.1.4", "@types/chroma-js": "^2.1.4",
"@types/file-saver": "^2.0.5", "@types/file-saver": "^2.0.5",
"@types/flat": "^5.0.2", "@types/flat": "^5.0.2",
@ -122,7 +122,7 @@
"flat": "^5.0.2", "flat": "^5.0.2",
"fs-extra": "^11.1.0", "fs-extra": "^11.1.0",
"lint-staged": "^13.1.0", "lint-staged": "^13.1.0",
"nuxt": "3.2.0", "nuxt": "3.2.2",
"prettier": "^2.8.3", "prettier": "^2.8.3",
"simple-git-hooks": "^2.8.1", "simple-git-hooks": "^2.8.1",
"typescript": "^4.9.5", "typescript": "^4.9.5",

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

@ -15,7 +15,7 @@ const reorderAndFilter = (items: mastodon.v1.Status[]) => reorderedTimeline(item
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

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

View file

@ -1,8 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
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

@ -1,6 +1,4 @@
<script setup lang="ts"> <script setup lang="ts">
import { useI18n } from 'vue-i18n'
definePageMeta({ definePageMeta({
middleware: 'auth', middleware: 'auth',
alias: ['/signin/callback'], alias: ['/signin/callback'],
@ -12,7 +10,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

@ -11,7 +11,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')}`,
}) })

File diff suppressed because it is too large Load diff