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