-
Notifications
You must be signed in to change notification settings - Fork 0
Add generateStaticParams and generateMetadata to fix Next.js build failure #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,33 @@ | ||
| import { source } from '@/lib/source'; | ||
| import { notFound } from 'next/navigation'; | ||
| import type { Metadata } from 'next'; | ||
|
|
||
| export const dynamicParams = true; | ||
| export const dynamic = 'force-dynamic'; | ||
| export const dynamicParams = false; | ||
|
|
||
| export function generateStaticParams() { | ||
| return source.generateParams(); | ||
| } | ||
|
|
||
| export async function generateMetadata(props: { | ||
| params: Promise<{ slug?: string[] }>; | ||
| }): Promise<Metadata> { | ||
| try { | ||
| const params = await props.params; | ||
| const page = source.getPage(params.slug); | ||
|
|
||
| if (!page) { | ||
| return {}; | ||
| } | ||
|
|
||
| return { | ||
| title: page.data.title || 'Documentation', | ||
| description: page.data.description || undefined, | ||
| }; | ||
| } catch (error) { | ||
| console.error('Error in generateMetadata:', error); | ||
| return {}; | ||
|
Comment on lines
+26
to
+28
|
||
| } | ||
| } | ||
|
|
||
| export default async function Page(props: { | ||
| params: Promise<{ slug?: string[] }>; | ||
|
|
@@ -16,6 +41,9 @@ export default async function Page(props: { | |
| return ( | ||
| <div className="container mx-auto px-4 py-8 max-w-4xl"> | ||
| <h1 className="text-3xl font-bold mb-4">{page.data.title || 'Untitled'}</h1> | ||
| {page.data.description && ( | ||
| <p className="text-lg text-gray-600 mb-6">{page.data.description}</p> | ||
| )} | ||
| <div className="prose prose-gray max-w-none"> | ||
| {MDX && <MDX />} | ||
| </div> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "title": "Documentation", | ||
| "pages": [ | ||
| "index", | ||
| "guide", | ||
| "spec" | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -14,7 +14,7 @@ | |||||
| "fumadocs-mdx": "^14.2.5", | ||||||
| "fumadocs-ui": "^15.0.0", | ||||||
| "lucide-react": "^0.344.0", | ||||||
| "next": "^15.1.6", | ||||||
| "next": "^15.3.0", | ||||||
|
||||||
| "next": "^15.3.0", | |
| "next": "15.3.0", |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is inconsistent error handling between generateMetadata and the Page component. In generateMetadata (line 18-19), when a page is not found, an empty metadata object is returned. However, in the Page component (line 37), the same condition triggers a notFound() call which returns a 404. This inconsistency means pages will be generated with empty metadata even though they don't exist. Consider calling notFound() in generateMetadata when page is null to maintain consistency.