💄 Allow slash as post divider

This commit is contained in:
LittleSheep 2024-08-17 22:38:13 +08:00
parent 2169e9c564
commit 0eaec5dd8d
6 changed files with 28 additions and 7 deletions

View File

@ -70,7 +70,8 @@
<script setup lang="ts">
definePageMeta({
layout: 'embed',
layout: "embed",
alias: ["/embed/posts/:area/:id"],
})
const route = useRoute()
@ -80,9 +81,17 @@ const attachments = ref<any[]>([])
const firstImage = ref<string | null>()
const firstVideo = ref<string | null>()
const slug = computed(() => {
if (route.params.area) {
return `${route.params.area}:${route.params.id}`
} else {
return route.params.id
}
})
const { t } = useI18n()
const { data: post } = await useFetch<any>(`${config.public.solarNetworkApi}/cgi/interactive/posts/${route.params.id}`)
const { data: post } = await useFetch<any>(`${config.public.solarNetworkApi}/cgi/interactive/posts/${slug.value}`)
if (!post.value) {
throw createError({
@ -132,5 +141,5 @@ useSeoMeta({
generator: "Solar Network Open Project · Embed Widget",
})
const externalOpenLink = computed(() => `${config.public.solianUrl}/posts/view/${route.params.id}`)
const externalOpenLink = computed(() => `${config.public.solianUrl}/posts/view/${slug.value}`)
</script>

View File

@ -69,6 +69,10 @@
</template>
<script setup lang="ts">
definePageMeta({
alias: ["/posts/:area/:id"],
})
const route = useRoute()
const config = useRuntimeConfig()
@ -76,9 +80,17 @@ const attachments = ref<any[]>([])
const firstImage = ref<string | null>()
const firstVideo = ref<string | null>()
const slug = computed(() => {
if (route.params.area) {
return `${route.params.area}:${route.params.id}`
} else {
return route.params.id
}
})
const { t } = useI18n()
const { data: post } = await useFetch<any>(`${config.public.solarNetworkApi}/cgi/interactive/posts/${route.params.id}`)
const { data: post } = await useFetch<any>(`${config.public.solarNetworkApi}/cgi/interactive/posts/${slug.value}`)
if (!post.value) {
throw createError({
@ -127,7 +139,7 @@ useSeoMeta({
ogSiteName: "Solsynth Capital",
})
const externalOpenLink = computed(() => `${config.public.solianUrl}/posts/view/${route.params.id}`)
const externalOpenLink = computed(() => `${config.public.solianUrl}/posts/view/${slug.value}`)
</script>
<style scoped>

View File

@ -5,7 +5,7 @@ export default defineSitemapEventHandler(async () => {
const result = await res.json()
return result.data.map((item: any) => asSitemapUrl({
loc: item.alias ? `/posts/${item.area_alias}:${item.alias}` : `/posts/${item.id}`,
loc: item.alias ? `/posts/${item.area_alias}/${item.alias}` : `/posts/${item.id}`,
lastmod: item.edited_at ?? item.published_at,
priority: 0.7,
_sitemap: "posts",

View File

@ -50,7 +50,7 @@ export default defineEventHandler(async (event) => {
.use(rehypeStringify)
.process(post.body.content)
const slug = post.alias ? `/posts/${post.area_alias}:${post.alias}` : `/posts/${post.id}`
const slug = post.alias ? `/posts/${post.area_alias}/${post.alias}` : `/posts/${post.id}`
feed.addItem({
date: new Date(post.published_at),