Skip to content

Commit 088754f

Browse files
feat(blog): refactor blog pagination and remove deprecated page component
1 parent 031cf59 commit 088754f

File tree

2 files changed

+8
-37
lines changed

2 files changed

+8
-37
lines changed

app/blog/page.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,24 @@ import ListLayout from '@/layouts/ListLayoutWithTags'
22
import { allCoreContent, sortPosts } from 'pliny/utils/contentlayer'
33
import { allBlogs } from 'contentlayer/generated'
44
import { genPageMetadata } from 'app/seo'
5+
import { notFound } from 'next/navigation'
56

67
const POSTS_PER_PAGE = 5
78

89
export const metadata = genPageMetadata({ title: 'Blog' })
910

10-
export default function BlogPage() {
11+
export default async function BlogPage(props: { searchParams: Promise<{ page: string }> }) {
1112
const posts = allCoreContent(sortPosts(allBlogs))
12-
const pageNumber = 1
13+
const searchParams = await props.searchParams
14+
const pageNumber = parseInt(searchParams.page || '1')
1315
const initialDisplayPosts = posts.slice(
1416
POSTS_PER_PAGE * (pageNumber - 1),
1517
POSTS_PER_PAGE * pageNumber
1618
)
19+
if (initialDisplayPosts.length === 0) {
20+
return notFound()
21+
}
22+
1723
const pagination = {
1824
currentPage: pageNumber,
1925
totalPages: Math.ceil(posts.length / POSTS_PER_PAGE),

app/blog/page/[page]/page.tsx

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)