blog/src/pages/posts/[slug].astro
radishzzz a26031d490 feat: add custom slug validation and handling for posts
- Enhance content configuration with slug validation to ensure only valid characters are used
- Update post routing to support custom slugs with fallback to default slug
- Implement slug duplication check to prevent conflicts across different languages
- Modify various page components to use custom or default slugs in URL generation
2025-01-25 03:14:52 +00:00

36 lines
865 B
Text

---
import Layout from '@/layouts/Layout.astro'
import { checkSlugDuplication } from '@/utils/content.config'
import { getCollection } from 'astro:content'
export async function getStaticPaths() {
const posts = await getCollection('posts')
const duplicates = await checkSlugDuplication(posts)
if (duplicates.length > 0) {
throw new Error(`Slug conflicts found:\n${duplicates.join('\n')}`)
}
return posts.map(post => ({
params: {
slug: post.data.slug || post.slug,
},
props: { post },
}))
}
const { post } = Astro.props
const { Content } = await post.render()
---
<Layout
postTitle={post.data.title}
postDescription={post.data.description}
postImage={post.data.image}
>
<article>
<h1>{post.data.title}</h1>
<time>{post.data.published.toISOString().split('T')[0]}</time>
<Content />
</article>
</Layout>