fix(posts): guard generateStaticParams against empty content dir
This commit is contained in:
@@ -10,6 +10,9 @@ export const dynamic = 'force-static'
|
||||
|
||||
export async function generateStaticParams() {
|
||||
const posts = await getPosts()
|
||||
if (posts.length === 0) {
|
||||
return [{ slug: '__no-posts__' }]
|
||||
}
|
||||
return posts.map((post) => ({ slug: post.slug }))
|
||||
}
|
||||
|
||||
@@ -22,6 +25,9 @@ export async function generateMetadata({ params }: { params: Promise<{ slug: str
|
||||
|
||||
export default async function PostPage({ params }: { params: Promise<{ slug: string }> }) {
|
||||
const slug = (await params).slug
|
||||
|
||||
if (slug === '__no-posts__') notFound()
|
||||
|
||||
const post = await getPost(slug)
|
||||
|
||||
if (!post) notFound()
|
||||
|
||||
Reference in New Issue
Block a user