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()
useHeadFixed({
useHead({
title: () => `${getDisplayName(status.account)} ${t('common.in')} ${t('app_name')}: "${removeHTMLTags(status.content) || ''}"`,
})

View file

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

View file

@ -1,8 +1,5 @@
import type { ComponentInternalInstance } 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)
@ -37,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 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": {
"@antfu/eslint-config": "^0.34.1",
"@antfu/ni": "^0.19.0",
"@antfu/ni": "^0.20.0",
"@types/chroma-js": "^2.1.4",
"@types/file-saver": "^2.0.5",
"@types/flat": "^5.0.2",
@ -122,7 +122,7 @@
"flat": "^5.0.2",
"fs-extra": "^11.1.0",
"lint-staged": "^13.1.0",
"nuxt": "3.2.0",
"nuxt": "3.2.2",
"prettier": "^2.8.3",
"simple-git-hooks": "^2.8.1",
"typescript": "^4.9.5",

View file

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

View file

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

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 })
if (account) {
useHeadFixed({
useHead({
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 })
if (account) {
useHeadFixed({
useHead({
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 })
if (account) {
useHeadFixed({
useHead({
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)
useHeadFixed({
useHead({
title: () => `${t('tab.posts')} | ${t('nav.explore')}`,
})
</script>

View file

@ -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')}`,
})
</script>

View file

@ -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')}`,
})
</script>

View file

@ -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')}`,
})
</script>

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,6 +1,4 @@
<script setup lang="ts">
import { useI18n } from 'vue-i18n'
definePageMeta({
middleware: 'auth',
alias: ['/signin/callback'],
@ -12,7 +10,7 @@ if (process.client && route.path === '/signin/callback')
router.push('/home')
const { t } = useI18n()
useHeadFixed({
useHead({
title: () => t('nav.home'),
})
</script>

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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(() => {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

File diff suppressed because it is too large Load diff