@@ -6,7 +6,6 @@ import { allBlogs } from 'contentlayer/generated'
66import tagData from 'app/tag-data.json'
77import { genPageMetadata } from 'app/seo'
88import { Metadata } from 'next'
9- import { notFound } from 'next/navigation'
109
1110const POSTS_PER_PAGE = 5
1211
@@ -30,37 +29,23 @@ export async function generateMetadata(props: {
3029export const generateStaticParams = async ( ) => {
3130 const tagCounts = tagData as Record < string , number >
3231 const tagKeys = Object . keys ( tagCounts )
33- const paths = tagKeys . map ( ( tag ) => ( {
32+ return tagKeys . map ( ( tag ) => ( {
3433 tag : encodeURI ( tag ) ,
3534 } ) )
36- return paths
3735}
3836
39- export default async function TagPage ( props : {
40- params : Promise < { tag : string } >
41- searchParams : Promise < { page : string } >
42- } ) {
37+ export default async function TagPage ( props : { params : Promise < { tag : string } > } ) {
4338 const params = await props . params
4439 const tag = decodeURI ( params . tag )
45- const searchParams = await props . searchParams
46- const pageNumber = parseInt ( searchParams . page || '1' )
47- // Capitalize first letter and convert space to dash
4840 const title = tag [ 0 ] . toUpperCase ( ) + tag . split ( ' ' ) . join ( '-' ) . slice ( 1 )
4941 const filteredPosts = allCoreContent (
5042 sortPosts ( allBlogs . filter ( ( post ) => post . tags && post . tags . map ( ( t ) => slug ( t ) ) . includes ( tag ) ) )
5143 )
52- const initialDisplayPosts = filteredPosts . slice (
53- POSTS_PER_PAGE * ( pageNumber - 1 ) ,
54- POSTS_PER_PAGE * pageNumber
55- )
56-
57- if ( initialDisplayPosts . length === 0 ) {
58- return notFound ( )
59- }
60-
44+ const totalPages = Math . ceil ( filteredPosts . length / POSTS_PER_PAGE )
45+ const initialDisplayPosts = filteredPosts . slice ( 0 , POSTS_PER_PAGE )
6146 const pagination = {
62- currentPage : pageNumber ,
63- totalPages : Math . ceil ( filteredPosts . length / POSTS_PER_PAGE ) ,
47+ currentPage : 1 ,
48+ totalPages : totalPages ,
6449 }
6550
6651 return (
0 commit comments