💄 Post path optimization

This commit is contained in:
2024-08-19 01:18:27 +08:00
parent ca253eb87b
commit b94e6906e1
8 changed files with 30 additions and 20 deletions

View File

@ -93,10 +93,17 @@ const { t } = useI18n()
const { data: post } = await useFetch<any>(`${config.public.solarNetworkApi}/cgi/co/posts/${slug.value}`)
if (!post.value) {
const { data: publisher } = await $fetch<any>(`${config.public.solarNetworkApi}/cgi/co/publishers/${route.params.id}`)
if (publisher) {
navigateTo(`/posts/publishers/${route.params.id}`)
}
throw createError({
statusCode: 404,
statusMessage: "Post Not Found",
})
} else if (post.value.alias) {
navigateTo(`/posts/${post.value.area_alias}/${post.value.alias}`)
}
const title = computed(() => post.value.body?.title ? `${post.value.body?.title} from ${post.value.author.nick}` : `Post from ${post.value.author.nick}`)

View File

@ -2,10 +2,11 @@
<v-container class="content-container mx-auto">
<div class="my-3 mx-[3.5ch]">
<h1 class="text-2xl">{{ t("navPosts") }}</h1>
<span>{{ t("navPostsCaptionWithRealm", [`#${route.params.id}`]) }}</span>
<span>{{ t("navPostsCaptionWithPublisher", [publisher.data.name]) }}</span>
</div>
<post-list :realm="route.params.id?.toString()" />
<post-list v-if="publisher.type == 'realm'" :realm="route.params.id?.toString()" />
<post-list v-else :author="route.params.id?.toString()" />
</v-container>
</template>
@ -13,13 +14,9 @@
const { t } = useI18n()
const route = useRoute()
const config = useRuntimeConfig()
if(Number.isNaN(parseInt(route.params.id?.toString()))) {
throw createError({
statusCode: 400,
statusMessage: "Realm ID must be a Number",
})
}
const { data: publisher } = useFetch<any>(`${config.public.solarNetworkApi}/cgi/co/publishers/${route.params.id}`)
useHead({
title: t("navPosts"),