Fix Invalid Tag Page Returns Status 200 Instead of 404 #988
This commit is contained in:
ray-android 2024-07-31 01:01:48 +08:00 committed by GitHub
parent 6b5287e066
commit 30e77eda9a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,6 +6,7 @@ import { allBlogs } from 'contentlayer/generated'
import tagData from 'app/tag-data.json'
import { genPageMetadata } from 'app/seo'
import { Metadata } from 'next'
import { notFound } from 'next/navigation'
export async function generateMetadata({ params }: { params: { tag: string } }): Promise<Metadata> {
const tag = decodeURI(params.tag)
@ -37,5 +38,8 @@ export default function TagPage({ params }: { params: { tag: string } }) {
const filteredPosts = allCoreContent(
sortPosts(allBlogs.filter((post) => post.tags && post.tags.map((t) => slug(t)).includes(tag)))
)
if (filteredPosts.length === 0) {
return notFound()
}
return <ListLayout posts={filteredPosts} title={title} />
}