36 lines
1.0 KiB
TypeScript
Raw Normal View History

2023-07-29 12:31:36 +08:00
import ListLayout from '@/layouts/ListLayoutWithTags'
import { allCoreContent, sortPosts } from 'pliny/utils/contentlayer'
2023-07-07 11:17:22 +08:00
import { allBlogs } from 'contentlayer/generated'
const POSTS_PER_PAGE = 5
export const generateStaticParams = async () => {
const totalPages = Math.ceil(allBlogs.length / POSTS_PER_PAGE)
2023-07-07 11:17:22 +08:00
const paths = Array.from({ length: totalPages }, (_, i) => ({ page: (i + 1).toString() }))
return paths
}
2024-10-31 22:37:40 +08:00
export default async function Page(props: { params: Promise<{ page: string }> }) {
const params = await props.params
const posts = allCoreContent(sortPosts(allBlogs))
2023-07-07 11:17:22 +08:00
const pageNumber = parseInt(params.page as string)
const initialDisplayPosts = posts.slice(
POSTS_PER_PAGE * (pageNumber - 1),
POSTS_PER_PAGE * pageNumber
)
const pagination = {
currentPage: pageNumber,
totalPages: Math.ceil(posts.length / POSTS_PER_PAGE),
}
return (
2023-07-16 18:52:51 +08:00
<ListLayout
posts={posts}
initialDisplayPosts={initialDisplayPosts}
2023-07-16 18:52:51 +08:00
pagination={pagination}
title="All Posts"
/>
2023-07-07 11:17:22 +08:00
)
}