fix draft post display and improve typings

This commit is contained in:
Timothy Lin
2023-07-26 00:49:18 +08:00
parent f133d76695
commit 7b56a4836b
6 changed files with 31 additions and 27 deletions

View File

@ -1,20 +1,18 @@
import ListLayout from '@/layouts/ListLayout'
import { allCoreContent, sortedBlogPost } from 'pliny/utils/contentlayer'
import { allCoreContent, sortPosts } 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 totalPages = Math.ceil(allBlogs.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 posts = allCoreContent(sortPosts(allBlogs))
const pageNumber = parseInt(params.page as string)
const initialDisplayPosts = posts.slice(
POSTS_PER_PAGE * (pageNumber - 1),
@ -27,8 +25,8 @@ export default function Page({ params }: { params: { page: string } }) {
return (
<ListLayout
posts={allCoreContent(posts)}
initialDisplayPosts={allCoreContent(initialDisplayPosts)}
posts={posts}
initialDisplayPosts={initialDisplayPosts}
pagination={pagination}
title="All Posts"
/>