tailwind-nextjs-blog/app/blog/page.tsx

31 lines
821 B
TypeScript
Raw Normal View History

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';
import { genPageMetadata } from 'app/seo';
2023-08-16 23:55:57 +08:00
const POSTS_PER_PAGE = 5;
2023-08-16 23:55:57 +08:00
export const metadata = genPageMetadata({ title: 'Blog' });
export default function BlogPage() {
2023-08-16 23:55:57 +08:00
const posts = allCoreContent(sortPosts(allBlogs));
const pageNumber = 1;
const initialDisplayPosts = posts.slice(
POSTS_PER_PAGE * (pageNumber - 1),
2023-08-16 23:55:57 +08:00
POSTS_PER_PAGE * pageNumber,
);
const pagination = {
currentPage: pageNumber,
totalPages: Math.ceil(posts.length / POSTS_PER_PAGE),
2023-08-16 23:55:57 +08:00
};
return (
<ListLayout
posts={posts}
initialDisplayPosts={initialDisplayPosts}
pagination={pagination}
title="All Posts"
/>
2023-08-16 23:55:57 +08:00
);
}