2023-08-16 23:55:57 +08:00
|
|
|
import ListLayout from '@/layouts/ListLayoutWithTags';
|
|
|
|
import { allCoreContent, sortPosts } from 'pliny/utils/contentlayer';
|
|
|
|
import { allBlogs } from 'contentlayer/generated';
|
2023-08-16 23:29:22 +08:00
|
|
|
|
2023-08-16 23:55:57 +08:00
|
|
|
const POSTS_PER_PAGE = 5;
|
2023-08-16 23:29:22 +08:00
|
|
|
|
|
|
|
export const generateStaticParams = async () => {
|
2023-08-16 23:55:57 +08:00
|
|
|
const totalPages = Math.ceil(allBlogs.length / POSTS_PER_PAGE);
|
|
|
|
const paths = Array.from({ length: totalPages }, (_, i) => ({
|
|
|
|
page: (i + 1).toString(),
|
|
|
|
}));
|
2023-08-16 23:29:22 +08:00
|
|
|
|
2023-08-16 23:55:57 +08:00
|
|
|
return paths;
|
|
|
|
};
|
2023-08-16 23:29:22 +08:00
|
|
|
|
|
|
|
export default function Page({ params }: { params: { page: string } }) {
|
2023-08-16 23:55:57 +08:00
|
|
|
const posts = allCoreContent(sortPosts(allBlogs));
|
|
|
|
const pageNumber = parseInt(params.page as string);
|
2023-08-16 23:29:22 +08:00
|
|
|
const initialDisplayPosts = posts.slice(
|
|
|
|
POSTS_PER_PAGE * (pageNumber - 1),
|
2023-08-16 23:55:57 +08:00
|
|
|
POSTS_PER_PAGE * pageNumber,
|
|
|
|
);
|
2023-08-16 23:29:22 +08:00
|
|
|
const pagination = {
|
|
|
|
currentPage: pageNumber,
|
|
|
|
totalPages: Math.ceil(posts.length / POSTS_PER_PAGE),
|
2023-08-16 23:55:57 +08:00
|
|
|
};
|
2023-08-16 23:29:22 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<ListLayout
|
|
|
|
posts={posts}
|
|
|
|
initialDisplayPosts={initialDisplayPosts}
|
|
|
|
pagination={pagination}
|
|
|
|
title="All Posts"
|
|
|
|
/>
|
2023-08-16 23:55:57 +08:00
|
|
|
);
|
2023-08-16 23:29:22 +08:00
|
|
|
}
|