|
| 1 | +import { getPageImage, source } from '@/lib/source'; |
| 2 | +import { |
| 3 | + DocsBody, |
| 4 | + DocsDescription, |
| 5 | + DocsPage, |
| 6 | + DocsTitle, |
| 7 | +} from 'fumadocs-ui/page'; |
| 8 | +import { notFound } from 'next/navigation'; |
| 9 | +import { getMDXComponents } from '@/mdx-components'; |
| 10 | +import type { Metadata } from 'next'; |
| 11 | +import { createRelativeLink } from 'fumadocs-ui/mdx'; |
| 12 | + |
| 13 | +export default async function Page(props: PageProps<'/docs/[[...slug]]'>) { |
| 14 | + const params = await props.params; |
| 15 | + const page = source.getPage(params.slug); |
| 16 | + if (!page) notFound(); |
| 17 | + |
| 18 | + const MDX = page.data.body; |
| 19 | + |
| 20 | + return ( |
| 21 | + <DocsPage toc={page.data.toc} full={page.data.full}> |
| 22 | + <DocsTitle>{page.data.title}</DocsTitle> |
| 23 | + <DocsDescription>{page.data.description}</DocsDescription> |
| 24 | + <DocsBody> |
| 25 | + <MDX |
| 26 | + components={getMDXComponents({ |
| 27 | + // this allows you to link to other pages with relative file paths |
| 28 | + a: createRelativeLink(source, page), |
| 29 | + })} |
| 30 | + /> |
| 31 | + </DocsBody> |
| 32 | + </DocsPage> |
| 33 | + ); |
| 34 | +} |
| 35 | + |
| 36 | +export async function generateStaticParams() { |
| 37 | + return source.generateParams(); |
| 38 | +} |
| 39 | + |
| 40 | +export async function generateMetadata( |
| 41 | + props: PageProps<'/docs/[[...slug]]'>, |
| 42 | +): Promise<Metadata> { |
| 43 | + const params = await props.params; |
| 44 | + const page = source.getPage(params.slug); |
| 45 | + if (!page) notFound(); |
| 46 | + |
| 47 | + return { |
| 48 | + title: page.data.title, |
| 49 | + description: page.data.description, |
| 50 | + openGraph: { |
| 51 | + images: getPageImage(page).url, |
| 52 | + }, |
| 53 | + }; |
| 54 | +} |
0 commit comments