Files
MyBlog-Next/src/pages/posts/[slug]/index.astro
T
Sat Naing 29eff36794 feat: add prev/next links at the bottom of blog post (#372)
* feat: add prev/next links at the bottom of blog post
* fix: update and rerun scripts in post details page after swap

Resolves #358
2024-09-16 20:43:54 +07:00

28 lines
653 B
Plaintext

---
import { type CollectionEntry, getCollection } from "astro:content";
import PostDetails from "@layouts/PostDetails.astro";
import getSortedPosts from "@utils/getSortedPosts";
export interface Props {
post: CollectionEntry<"blog">;
}
export async function getStaticPaths() {
const posts = await getCollection("blog", ({ data }) => !data.draft);
const postResult = posts.map(post => ({
params: { slug: post.slug },
props: { post },
}));
return postResult;
}
const { post } = Astro.props;
const posts = await getCollection("blog");
const sortedPosts = getSortedPosts(posts);
---
<PostDetails post={post} posts={sortedPosts} />