diff --git a/dashboard/src/app/blog/page.tsx b/dashboard/src/app/blog/page.tsx index 0040e6c..75f0813 100644 --- a/dashboard/src/app/blog/page.tsx +++ b/dashboard/src/app/blog/page.tsx @@ -1,6 +1,7 @@ import Link from 'next/link' import { getHomepagePosts } from '@cms/content' import type { Metadata } from 'next' +import { notFound } from 'next/navigation' export const metadata: Metadata = { title: 'Blog | Cloud-Neutral', @@ -27,8 +28,23 @@ function formatDate(dateStr: string | undefined, language: 'zh' | 'en'): string } } -export default async function BlogPage() { +type PageProps = { + searchParams: { page?: string } +} + +export default async function BlogPage({ searchParams }: PageProps) { const posts = await getHomepagePosts() + const postsPerPage = 10 + const currentPage = parseInt(searchParams.page || '1', 10) + const totalPages = Math.ceil(posts.length / postsPerPage) + + if (currentPage < 1 || currentPage > totalPages) { + notFound() + } + + const startIndex = (currentPage - 1) * postsPerPage + const endIndex = startIndex + postsPerPage + const paginatedPosts = posts.slice(startIndex, endIndex) return (
@@ -45,48 +61,92 @@ export default async function BlogPage() {

暂无博客文章

) : ( -
- {posts.map((post) => ( -
-
- Blog - {post.date && ( - - )} -
-

{post.title}

- {post.author && ( -

By {post.author}

- )} -

{post.excerpt}

-
- {post.tags && post.tags.length > 0 && ( -
- {post.tags.map((tag) => ( - - {tag} - - ))} -
+ <> +
+ {paginatedPosts.map((post) => ( +
+
+ Blog + {post.date && ( + + )} +
+

{post.title}

+ {post.author && ( +

By {post.author}

)} +

{post.excerpt}

+
+ {post.tags && post.tags.length > 0 && ( +
+ {post.tags.map((tag) => ( + + {tag} + + ))} +
+ )} + + Read more → + +
+
+ ))} +
+ + {totalPages > 1 && ( +
-
- ))} -
+ ))} + + + Next + + + )} + )}