mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 11:29:33 +08:00
refactor: replace pagination logic with Astro built-in pagination (#376)
This commit is contained in:
committed by
GitHub
parent
70b2486293
commit
08b1676cdd
@@ -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} />
|
||||
|
||||
Reference in New Issue
Block a user