Skip to content

Commit

Permalink
Update [...slug].astro
Browse files Browse the repository at this point in the history
  • Loading branch information
devthedevel committed Jan 11, 2024
1 parent 197eebd commit 3018dcb
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/pages/blog/[...slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@ import { type CollectionEntry, getCollection } from 'astro:content';
import BlogPost from '../../layouts/BlogPost.astro';
export async function getStaticPaths() {
const posts = await getCollection('blog');
return posts.map((post) => ({
type BlogCollection = CollectionEntry<'blog'>
const blogCollection: BlogCollection = await getCollection('blog')
const blogPosts = Array.isArray(blogCollection) ? blogCollection : []
return blogPosts.map((post) => ({
params: { slug: post.slug },
props: post,
}));
}
type Props = CollectionEntry<'blog'>;
const post = Astro.props;
// @ts-ignore - 404 page will catch any runtime errors
const { Content } = await post.render();
---

<BlogPost {...post.data}>
<BlogPost {
// @ts-ignore
...post.data
}>
<Content />
</BlogPost>

0 comments on commit 3018dcb

Please sign in to comment.