File tree Expand file tree Collapse file tree 2 files changed +8
-37
lines changed Expand file tree Collapse file tree 2 files changed +8
-37
lines changed Original file line number Diff line number Diff line change @@ -2,18 +2,24 @@ import ListLayout from '@/layouts/ListLayoutWithTags'
2
2
import { allCoreContent , sortPosts } from 'pliny/utils/contentlayer'
3
3
import { allBlogs } from 'contentlayer/generated'
4
4
import { genPageMetadata } from 'app/seo'
5
+ import { notFound } from 'next/navigation'
5
6
6
7
const POSTS_PER_PAGE = 5
7
8
8
9
export const metadata = genPageMetadata ( { title : 'Blog' } )
9
10
10
- export default function BlogPage ( ) {
11
+ export default async function BlogPage ( props : { searchParams : Promise < { page : string } > } ) {
11
12
const posts = allCoreContent ( sortPosts ( allBlogs ) )
12
- const pageNumber = 1
13
+ const searchParams = await props . searchParams
14
+ const pageNumber = parseInt ( searchParams . page || '1' )
13
15
const initialDisplayPosts = posts . slice (
14
16
POSTS_PER_PAGE * ( pageNumber - 1 ) ,
15
17
POSTS_PER_PAGE * pageNumber
16
18
)
19
+ if ( initialDisplayPosts . length === 0 ) {
20
+ return notFound ( )
21
+ }
22
+
17
23
const pagination = {
18
24
currentPage : pageNumber ,
19
25
totalPages : Math . ceil ( posts . length / POSTS_PER_PAGE ) ,
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments