Skip to content

Commit

Permalink
feat(blog): refactor blog pagination and remove deprecated page compo…
Browse files Browse the repository at this point in the history
…nent
  • Loading branch information
shelton-xiaoteng-ma committed Jan 6, 2025
1 parent 031cf59 commit 088754f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 37 deletions.
10 changes: 8 additions & 2 deletions app/blog/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@ import ListLayout from '@/layouts/ListLayoutWithTags'
import { allCoreContent, sortPosts } from 'pliny/utils/contentlayer'
import { allBlogs } from 'contentlayer/generated'
import { genPageMetadata } from 'app/seo'
import { notFound } from 'next/navigation'

const POSTS_PER_PAGE = 5

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

export default function BlogPage() {
export default async function BlogPage(props: { searchParams: Promise<{ page: string }> }) {
const posts = allCoreContent(sortPosts(allBlogs))
const pageNumber = 1
const searchParams = await props.searchParams
const pageNumber = parseInt(searchParams.page || '1')
const initialDisplayPosts = posts.slice(
POSTS_PER_PAGE * (pageNumber - 1),
POSTS_PER_PAGE * pageNumber
)
if (initialDisplayPosts.length === 0) {
return notFound()
}

const pagination = {
currentPage: pageNumber,
totalPages: Math.ceil(posts.length / POSTS_PER_PAGE),
Expand Down
35 changes: 0 additions & 35 deletions app/blog/page/[page]/page.tsx

This file was deleted.

0 comments on commit 088754f

Please sign in to comment.