37 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-07-07 11:17:22 +08:00
import ListLayout from '@/layouts/ListLayout'
import { allCoreContent, sortedBlogPost } from 'pliny/utils/contentlayer'
import { allBlogs } from 'contentlayer/generated'
import type { Blog } from 'contentlayer/generated'
const POSTS_PER_PAGE = 5
export const generateStaticParams = async () => {
const totalPosts = allBlogs
const totalPages = Math.ceil(totalPosts.length / POSTS_PER_PAGE)
const paths = Array.from({ length: totalPages }, (_, i) => ({ page: (i + 1).toString() }))
return paths
}
export default function Page({ params }: { params: { page: string } }) {
const posts = sortedBlogPost(allBlogs) as Blog[]
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={allCoreContent(posts)}
initialDisplayPosts={allCoreContent(initialDisplayPosts)}
pagination={pagination}
title="All Posts"
/>
2023-07-07 11:17:22 +08:00
)
}