Files
blog/src/pages/posts/[...slug].astro
2025-11-21 11:51:31 +08:00

25 lines
536 B
Plaintext

---
import { getCollection, getEntry } from 'astro:content';
import PostLayout from '@/layouts/PostLayout.astro';
import { getReadingTime } from '@/utils/reading-time';
const { slug } = Astro.params;
if (!slug) {
return Astro.redirect('/404');
}
const post = await getEntry('posts', slug);
if (!post || post.data.draft) {
return Astro.redirect('/404');
}
const { Content } = await post.render();
const readingTime = getReadingTime(post.body);
---
<PostLayout post={post} readingTime={readingTime}>
<Content />
</PostLayout>