diff --git a/src/components/PaginateButton.astro b/src/components/PaginateButton.astro new file mode 100644 index 0000000..322811b --- /dev/null +++ b/src/components/PaginateButton.astro @@ -0,0 +1,27 @@ +--- +// SPDX-FileCopyrightText: 2025 Norbert Melzer +// SPDX-FileContributor: Norbert Melzer +// +// SPDX-License-Identifier: MIT + +export type Props = { + href?: string; +}; + +const { href } = Astro.props; + +const active = !!href; +--- + +
+ +
diff --git a/src/pages/blog/[page].astro b/src/pages/blog/[page].astro new file mode 100644 index 0000000..839dffc --- /dev/null +++ b/src/pages/blog/[page].astro @@ -0,0 +1,39 @@ +--- +// SPDX-FileCopyrightText: 2025 Norbert Melzer +// SPDX-FileContributor: Norbert Melzer +// +// SPDX-License-Identifier: MIT + +import { getCollection } from "astro:content"; +import type { CollectionEntry } from "astro:content"; +import type { GetStaticPaths } from "astro"; + +import PostPreview from "../../components/PostPreview.astro"; +import PaginateButton from "../../components/PaginateButton.astro"; +import NobbzDev from "../../layouts/NobbzDev.astro"; + +export const getStaticPaths = (async ({ paginate }) => { + const blogEntries = await getCollection("blog").then( + (collection: CollectionEntry<"blog">[]) => + collection.sort((a, b) => b.data.date.getTime() - a.data.date.getTime()), + ); + return paginate(blogEntries, { pageSize: 5 }); +}) satisfies GetStaticPaths; + +const { page } = Astro.props; + +const blogEntries = page.data; +--- + + + {blogEntries.map((post) => )} + + +
+ << + < + > + >> +
+
diff --git a/src/pages/blog/index.astro b/src/pages/blog/index.astro index cb3b59c..47e106f 100644 --- a/src/pages/blog/index.astro +++ b/src/pages/blog/index.astro @@ -4,16 +4,5 @@ // // SPDX-License-Identifier: MIT -import { getCollection } from "astro:content"; - -import PostPreview from "../../components/PostPreview.astro"; -import NobbzDev from "../../layouts/NobbzDev.astro"; - -const blogEntries = await getCollection("blog").then((collection) => - collection.sort((a, b) => b.data.date.getTime() - a.data.date.getTime()), -); +return Astro.rewrite('/blog/1') --- - - - {blogEntries.map((post) => )} -