|
| 1 | +import { getMDXComponents } from 'components/mdx'; |
| 2 | +import { |
| 3 | + DocsBody, |
| 4 | + DocsDescription, |
| 5 | + DocsPage, |
| 6 | + DocsTitle, |
| 7 | + MarkdownCopyButton, |
| 8 | + ViewOptionsPopover, |
| 9 | +} from 'fumadocs-ui/layouts/docs/page'; |
| 10 | +import { createRelativeLink } from 'fumadocs-ui/mdx'; |
| 11 | +import { gitConfig } from 'lib/layout.shared'; |
| 12 | +import { getPageImage, source } from 'lib/source'; |
| 13 | +import type { Metadata } from 'next'; |
| 14 | +import { notFound } from 'next/navigation'; |
| 15 | + |
| 16 | +export default async function Page({ params }: PageProps<'/[...slug]'>) { |
| 17 | + const { slug } = await params; |
| 18 | + const page = source.getPage(slug); |
| 19 | + if (!page) notFound(); |
| 20 | + |
| 21 | + const MDX = page.data.body; |
| 22 | + |
| 23 | + return ( |
| 24 | + <DocsPage toc={page.data.toc} full={page.data.full}> |
| 25 | + <DocsTitle>{page.data.title}</DocsTitle> |
| 26 | + <DocsDescription className="mb-0">{page.data.description}</DocsDescription> |
| 27 | + <div className="flex flex-row gap-2 items-center border-b pb-6"> |
| 28 | + <MarkdownCopyButton markdownUrl={`${page.url}.mdx`} /> |
| 29 | + <ViewOptionsPopover |
| 30 | + markdownUrl={`${page.url}.mdx`} |
| 31 | + githubUrl={`https://github.com/${gitConfig.user}/${gitConfig.repo}/blob/${gitConfig.branch}/content/docs/${page.path}`} |
| 32 | + /> |
| 33 | + </div> |
| 34 | + <DocsBody> |
| 35 | + <MDX |
| 36 | + components={getMDXComponents({ |
| 37 | + // this allows you to link to other pages with relative file paths |
| 38 | + a: createRelativeLink(source, page), |
| 39 | + })} |
| 40 | + /> |
| 41 | + </DocsBody> |
| 42 | + </DocsPage> |
| 43 | + ); |
| 44 | +} |
| 45 | + |
| 46 | +export async function generateStaticParams() { |
| 47 | + return source.generateParams(); |
| 48 | +} |
| 49 | + |
| 50 | +export async function generateMetadata({ params }: PageProps<'/[...slug]'>): Promise<Metadata> { |
| 51 | + const { slug } = await params; |
| 52 | + const page = source.getPage(slug); |
| 53 | + if (!page) notFound(); |
| 54 | + |
| 55 | + return { |
| 56 | + title: page.data.title, |
| 57 | + description: page.data.description, |
| 58 | + openGraph: { |
| 59 | + images: getPageImage(page).url, |
| 60 | + }, |
| 61 | + }; |
| 62 | +} |
0 commit comments