0
mirror of https://github.com/valentineus/popov.link.git synced 2025-07-04 08:30:27 +03:00

Add PostPagination component for blog post navigation

This commit is contained in:
2024-09-12 14:06:44 +00:00
parent 4ba339984d
commit 0b57b888ca
2 changed files with 61 additions and 3 deletions

View File

@ -2,17 +2,24 @@
import { type CollectionEntry, getCollection } from "astro:content";
import Comments from "../../components/Comments.astro";
import Layout from "../../layouts/PageLayout.astro";
import Pagination from "../../components/PostPagination.astro";
export async function getStaticPaths() {
const posts = await getCollection("blog");
return posts.map((post) => ({
const total = posts.length;
return posts.map((post, index) => ({
params: { slug: post.slug },
props: post,
props: {
post,
prevPost: index + 1 === total ? null : posts[index + 1],
nextPost: index === 0 ? null : posts[index - 1],
},
}));
}
type Props = CollectionEntry<"blog">;
const post = Astro.props;
const { post, prevPost, nextPost } = Astro.props;
const { Content, remarkPluginFrontmatter } = await post.render();
---
@ -40,6 +47,10 @@ const { Content, remarkPluginFrontmatter } = await post.render();
<Content />
</section>
<section>
<Pagination prevPost={prevPost} nextPost={nextPost} />
</section>
<section>
<Comments />
</section>