From 8c73ec7d8e79c3b20d315d9c5a39329702f1b346 Mon Sep 17 00:00:00 2001
From: Dorian Niemiec
Date: Sat, 7 Sep 2024 14:24:30 +0200
Subject: [PATCH] feat: make blog index page statically generated
---
app/(root)/blog/page.tsx | 10 +---
app/(root)/blog/page/[id]/page.tsx | 80 ++++++++++++++++++++++++++++++
components/cards/BlogCards.tsx | 16 +++---
3 files changed, 91 insertions(+), 15 deletions(-)
create mode 100644 app/(root)/blog/page/[id]/page.tsx
diff --git a/app/(root)/blog/page.tsx b/app/(root)/blog/page.tsx
index 03520dc..5a1df4b 100644
--- a/app/(root)/blog/page.tsx
+++ b/app/(root)/blog/page.tsx
@@ -35,13 +35,7 @@ export const metadata: Metadata = {
}
};
-const BlogPage = async ({
- searchParams
-}: {
- searchParams: { page?: string };
-}) => {
- // Optionally, you can fetch some initial data here if needed.
-
+const BlogPage = async () => {
return (
-
+
+ SVR.JS Blog Post
+
+
+ Stay updated with our latest blog posts by subscribing to our
+
+
+
+
+
+
+ );
+};
+
+export async function generateStaticParams() {
+ // Change in BlogCards component too!
+ const cardsPerPage = 6;
+
+ const totalPostsQuery = `count(*[_type == 'blog'])`;
+ const totalPosts: number = await client.fetch(totalPostsQuery);
+
+ const totalPages = Math.ceil(totalPosts / cardsPerPage);
+
+ let ids: any[] = [];
+ for (let i = 1; i <= totalPages; i++) {
+ ids.push({ id: i.toString() });
+ }
+
+ return ids;
+}
+
+export default BlogPage;
diff --git a/components/cards/BlogCards.tsx b/components/cards/BlogCards.tsx
index 024abfd..7da8120 100644
--- a/components/cards/BlogCards.tsx
+++ b/components/cards/BlogCards.tsx
@@ -22,14 +22,16 @@ interface BlogPostcard {
_createdAt: string;
}
-interface BlogCardsProps {
- searchParams: { page?: string };
+interface BlogCardInterface {
+ page: number;
}
-const BlogCards: React.FC