aboutsummaryrefslogtreecommitdiff
path: root/src/pages
diff options
context:
space:
mode:
Diffstat (limited to 'src/pages')
-rw-r--r--src/pages/[...page].astro30
-rw-r--r--src/pages/index.astro14
2 files changed, 30 insertions, 14 deletions
diff --git a/src/pages/[...page].astro b/src/pages/[...page].astro
new file mode 100644
index 0000000..23a5d51
--- /dev/null
+++ b/src/pages/[...page].astro
@@ -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>
diff --git a/src/pages/index.astro b/src/pages/index.astro
deleted file mode 100644
index 6575ca6..0000000
--- a/src/pages/index.astro
+++ /dev/null
@@ -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>