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

Added Pagination component

This commit is contained in:
2024-09-12 22:10:31 +00:00
parent 3591bebabf
commit de1885fe8f
5 changed files with 82 additions and 14 deletions

30
src/pages/[...page].astro Normal file
View File

@ -0,0 +1,30 @@
---
import type { GetStaticPaths, InferGetStaticPropsType } from "astro";
import { getCollection } from "astro:content";
import Layout from "../layouts/BaseLayout.astro";
import Pagination from "../components/Pagination.astro";
import PostSummary from "../components/PostSummary.astro";
export const getStaticPaths = (async ({ paginate }) => {
const posts = await getCollection("blog");
posts.sort((a, b) => b.data.pubDate.getTime() - a.data.pubDate.getTime());
return paginate(posts, {
pageSize: 5,
});
}) satisfies GetStaticPaths;
type Props = InferGetStaticPropsType<typeof getStaticPaths>;
const { page } = Astro.props;
---
<Layout>
<section>
{page.data.map((post) => <PostSummary post={post} />)}
</section>
<section>
<Pagination prevUrl={page.url.prev} nextUrl={page.url.next} />
</section>
</Layout>

View File

@ -1,14 +0,0 @@
---
import { getCollection } from "astro:content";
import Element from "../components/PostElement.astro";
import Layout from "../layouts/BaseLayout.astro";
const posts = await getCollection("blog");
posts.sort((a, b) => b.data.pubDate.getTime() - a.data.pubDate.getTime());
---
<Layout>
<section>
{posts.map((post) => <Element post={post} />)}
</section>
</Layout>