-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: seperated mock data into its own file, generated staticParams f…
…or articles
- Loading branch information
1 parent
8996a36
commit 0950bdb
Showing
8 changed files
with
213 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,42 @@ | ||
export function generateMetadata() { | ||
import { articleMockData as articleData } from '@/mock-data/article'; | ||
import { unstable_setRequestLocale } from 'next-intl/server'; | ||
import { notFound } from 'next/navigation'; | ||
|
||
export async function generateStaticParams() { | ||
return articleData.map((article) => ({ | ||
article: String(article.id), | ||
})); | ||
} | ||
|
||
export async function generateMetadata({ | ||
params, | ||
}: { | ||
params: { article: string }; | ||
}) { | ||
const article = articleData.find( | ||
(article) => article.id === Number(params.article), | ||
); | ||
|
||
return { | ||
title: 'Test', | ||
title: article?.title, | ||
}; | ||
} | ||
|
||
export default function Article() { | ||
return null; | ||
export default function Article({ | ||
params, | ||
}: { | ||
params: { locale: string; article: string }; | ||
}) { | ||
unstable_setRequestLocale(params.locale); | ||
const article = articleData.find( | ||
(article) => article.id === Number(params.article), | ||
); | ||
if (!article) { | ||
return notFound(); | ||
} | ||
return ( | ||
<> | ||
<h2 className='first:my-4'>{article.title}</h2> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.