refactor: replace pagination logic with Astro built-in pagination (#376)

This commit is contained in:
Timon Jurschitsch
2024-09-16 08:05:50 +02:00
committed by GitHub
parent 70b2486293
commit 08b1676cdd
12 changed files with 102 additions and 195 deletions
+2 -20
View File
@@ -1,10 +1,6 @@
---
import { type CollectionEntry, getCollection } from "astro:content";
import Posts from "@layouts/Posts.astro";
import PostDetails from "@layouts/PostDetails.astro";
import getSortedPosts from "@utils/getSortedPosts";
import getPageNumbers from "@utils/getPageNumbers";
import getPagination from "@utils/getPagination";
export interface Props {
post: CollectionEntry<"blog">;
@@ -18,24 +14,10 @@ export async function getStaticPaths() {
props: { post },
}));
const pagePaths = getPageNumbers(posts.length).map(pageNum => ({
params: { slug: String(pageNum) },
}));
return [...postResult, ...pagePaths];
return postResult;
}
const { slug } = Astro.params;
const { post } = Astro.props;
const posts = await getCollection("blog");
const sortedPosts = getSortedPosts(posts);
const pagination = getPagination({
posts: sortedPosts,
page: slug,
});
---
{post ? <PostDetails post={post} /> : <Posts {...pagination} />}
<PostDetails post={post} />