|
| 1 | +import browserCollections from "fumadocs-mdx:collections/browser"; |
| 2 | +import type * as PageTree from "fumadocs-core/page-tree"; |
| 3 | +import * as TabsComponents from "fumadocs-ui/components/tabs"; |
| 4 | +import { DocsLayout } from "fumadocs-ui/layouts/docs"; |
| 5 | +import defaultMdxComponents from "fumadocs-ui/mdx"; |
| 6 | +import { |
| 7 | + DocsBody, |
| 8 | + DocsDescription, |
| 9 | + DocsPage, |
| 10 | + DocsTitle, |
| 11 | +} from "fumadocs-ui/page"; |
| 12 | +import { baseOptions } from "@/lib/layout.shared"; |
| 13 | +import { source } from "@/lib/source"; |
| 14 | +import type { Route } from "./+types/page"; |
| 15 | + |
| 16 | +export async function loader({ params }: Route.LoaderArgs) { |
| 17 | + const slugs = params["*"].split("/").filter((v) => v.length > 0); |
| 18 | + const page = source.getPage(slugs); |
| 19 | + if (!page) throw new Response("Not found", { status: 404 }); |
| 20 | + |
| 21 | + return { |
| 22 | + path: page.path, |
| 23 | + tree: source.getPageTree(), |
| 24 | + }; |
| 25 | +} |
| 26 | + |
| 27 | +const clientLoader = browserCollections.docs.createClientLoader({ |
| 28 | + component({ toc, default: Mdx, frontmatter }) { |
| 29 | + return ( |
| 30 | + <DocsPage toc={toc}> |
| 31 | + <title>{frontmatter.title}</title> |
| 32 | + <meta name="description" content={frontmatter.description} /> |
| 33 | + <DocsTitle>{frontmatter.title}</DocsTitle> |
| 34 | + <DocsDescription>{frontmatter.description}</DocsDescription> |
| 35 | + <DocsBody> |
| 36 | + <Mdx components={{ ...defaultMdxComponents, ...TabsComponents }} /> |
| 37 | + </DocsBody> |
| 38 | + </DocsPage> |
| 39 | + ); |
| 40 | + }, |
| 41 | +}); |
| 42 | + |
| 43 | +export default function Page({ loaderData }: Route.ComponentProps) { |
| 44 | + const { tree, path } = loaderData; |
| 45 | + const Content = clientLoader.getComponent(path); |
| 46 | + |
| 47 | + return ( |
| 48 | + <DocsLayout {...baseOptions()} tree={tree as PageTree.Root}> |
| 49 | + <Content /> |
| 50 | + </DocsLayout> |
| 51 | + ); |
| 52 | +} |
0 commit comments