1
1
import React from 'react' ;
2
2
import { Card } from '@/components/Card/Card' ;
3
3
import _ from 'lodash' ;
4
- import { allPosts , Post } from 'contentlayer/generated' ;
4
+ import { allPosts } from 'contentlayer/generated' ;
5
5
import type { Metadata } from 'next'
6
+ import type { Post } from 'contentlayer/generated' ;
7
+ import { notFound } from 'next/navigation' ;
8
+
6
9
7
10
export async function generateMetadata ( { params } : { params : Promise < { slug : string } > } ) : Promise < Metadata > {
8
11
const { slug } = await params
@@ -17,7 +20,7 @@ export async function generateStaticParams() {
17
20
allPosts . map (
18
21
item => {
19
22
if ( item . author !== undefined ) {
20
- paths . push ( { slug : item . author ?. name . trim ( ) . toLowerCase ( ) . replaceAll ( " " , "-" ) } )
23
+ paths . push ( { slug : item . author ?. trim ( ) . toLowerCase ( ) . replaceAll ( " " , "-" ) } )
21
24
}
22
25
}
23
26
)
@@ -29,18 +32,19 @@ export async function generateStaticParams() {
29
32
)
30
33
return RemoveDuplicateAuthor
31
34
}
32
- export default async function Page ( { params } : { params : Promise < { slug : string } > } ) {
35
+ export default async function Page ( { params } : { params : Promise < { slug : string } > } ) {
33
36
34
37
const slug = ( await params ) . slug
35
38
36
39
const AuthorPosts : Post [ ] = allPosts . filter ( ( post ) => {
37
40
if ( post . author !== undefined ) {
38
- if ( post . author ?. name . trim ( ) . toLowerCase ( ) . replaceAll ( " " , "-" ) === slug ) return post
41
+ if ( post . author ?. trim ( ) . toLowerCase ( ) . replaceAll ( " " , "-" ) === slug ) return post
39
42
}
40
43
} )
41
44
42
- if ( AuthorPosts . length === 0 ) throw new Error ( `Author not found for slug: ${ slug } ` )
43
-
45
+ if ( AuthorPosts . length === 0 ) {
46
+ notFound ( )
47
+ }
44
48
45
49
return (
46
50
< section className = "py-32" >
0 commit comments