💄 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

@ -94,10 +94,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 @@
<div>
<div class="my-3" v-if="!route.query['no-title']">
<h1 class="text-2xl">{{ route.query["title"] ?? t("navPosts") }}</h1>
<span>{{ route.query["caption"] ?? t("navPostsCaptionWithRealm", [`#${route.params.id}`]) }}</span>
<span>{{ route.query["caption"] ?? t("navPostsCaptionWithPublisher", [publisher.data.name]) }}</span>
</div>
<post-list class="mx-[-2.5ch]" :realm-id="parseInt(route.params.id?.toString())" />
<post-list v-if="publisher.type == 'realm'" class="mx-[-2.5ch]" :realm="route.params.id?.toString()" />
<post-list v-else class="mx-[-2.5ch]" :author="route.params.id?.toString()" />
</div>
</template>
@ -17,13 +18,9 @@ definePageMeta({
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"),