diff --git a/src/pages/blog.astro b/src/pages/blog.astro deleted file mode 100644 index a48cbe4..0000000 --- a/src/pages/blog.astro +++ /dev/null @@ -1,32 +0,0 @@ ---- -import { getCollection } from "astro:content"; -import BaseLayout from "../layouts/BaseLayout.astro"; -import BlogPost from "../components/BlogPost.astro"; - -const allPosts = await getCollection("blog"); -const pageTitle = "Latest Posts"; ---- - - - -
- { - allPosts.map((post: any) => ( - - )) - } -
-
diff --git a/src/pages/blog/[...page].astro b/src/pages/blog/[...page].astro new file mode 100644 index 0000000..c5b361c --- /dev/null +++ b/src/pages/blog/[...page].astro @@ -0,0 +1,126 @@ +--- +import { getCollection } from "astro:content"; +import BaseLayout from "../../layouts/BaseLayout.astro"; +import BlogPost from "../../components/BlogPost.astro"; + +type Page = { + data: T[]; + currentPage: number; + lastPage: number; + url: { + current: string; + first?: string; + prev?: string; + next?: string; + last?: string; + }; +}; + +type BlogPostEntry = { + id: string; + data: { + title: string; + pubDate: Date; + }; +}; + +interface Props { + page: Page; +} + +export async function getStaticPaths({ + paginate +} : { + paginate: (data: any[], options?: { pageSize?: number; params?: Record; props?: Record }) => any; +}) { + const allPosts = await getCollection("blog"); + + allPosts.sort( + (a, b) => new Date(b.data.pubDate).getTime() - new Date(a.data.pubDate).getTime() + ); + + return paginate( + allPosts, + { + pageSize: 6, + } + ); +} + +const { page } = Astro.props as Props; +const pageTitle = "Articles"; +--- + + + + +
+ { + page.data.map((post) => ( + + )) + } +
+ + +