mirror of
https://github.com/reonokiy/blog.nokiy.net.git
synced 2025-06-16 11:41:17 +02:00
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
This commit is contained in:
parent
ee35006f7c
commit
a26031d490
10 changed files with 67 additions and 11 deletions
|
@ -1,11 +1,20 @@
|
|||
---
|
||||
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.slug },
|
||||
params: {
|
||||
slug: post.data.slug || post.slug,
|
||||
},
|
||||
props: { post },
|
||||
}))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue