mirror of
https://github.com/ReaJason/MemShellParty.git
synced 2026-09-21 22:50:42 +08:00
68 lines
2.2 KiB
TypeScript
68 lines
2.2 KiB
TypeScript
import type { Route } from "./+types/page";
|
|
|
|
import { useFumadocsLoader } from "fumadocs-core/source/client";
|
|
import { DocsLayout } from "fumadocs-ui/layouts/docs";
|
|
import {
|
|
DocsBody,
|
|
DocsDescription,
|
|
DocsPage,
|
|
DocsTitle,
|
|
MarkdownCopyButton,
|
|
ViewOptionsPopover,
|
|
} from "fumadocs-ui/layouts/docs/page";
|
|
import { use } from "react";
|
|
|
|
import { useMDXComponents } from "@/components/mdx";
|
|
import { baseOptions } from "@/lib/layout.shared";
|
|
import { docs, getPageMarkdownUrl, source } from "@/lib/source";
|
|
|
|
export async function loader({ params }: Route.LoaderArgs) {
|
|
const slugs = params["*"].split("/").filter((v) => v.length > 0);
|
|
const page = source.getPage(slugs);
|
|
if (!page) throw new Response("Not found", { status: 404 });
|
|
|
|
return {
|
|
path: page.path,
|
|
markdownUrl: getPageMarkdownUrl(page).url,
|
|
pageTree: await source.serializePageTree(source.getPageTree()),
|
|
};
|
|
}
|
|
|
|
function Content({ path, markdownUrl }: { path: string; markdownUrl: string }) {
|
|
const page = docs.getPage(path);
|
|
if (!page) throw new Error(`unknown page: ${path}`);
|
|
|
|
// content is loaded lazily, call `page.preload()` in the loader to avoid suspending
|
|
const { toc } = use(page.load());
|
|
const Mdx = page.body;
|
|
|
|
return (
|
|
<DocsPage toc={toc} tableOfContent={{ style: "clerk" }}>
|
|
<title>{page.title}</title>
|
|
<meta name="description" content={page.description} />
|
|
<DocsTitle>{page.title}</DocsTitle>
|
|
<DocsDescription>{page.description}</DocsDescription>
|
|
<div className="-mt-4 flex flex-row items-center gap-2 border-b pb-6">
|
|
<MarkdownCopyButton markdownUrl={markdownUrl} />
|
|
<ViewOptionsPopover
|
|
markdownUrl={markdownUrl}
|
|
githubUrl={`https://github.com/ReaJason/MemShellParty/blob/master/web/content/docs/${path}`}
|
|
/>
|
|
</div>
|
|
<DocsBody>
|
|
<Mdx components={useMDXComponents()} />
|
|
</DocsBody>
|
|
</DocsPage>
|
|
);
|
|
}
|
|
|
|
export default function Page({ loaderData }: Route.ComponentProps) {
|
|
const { pageTree, path, markdownUrl } = useFumadocsLoader(loaderData);
|
|
|
|
return (
|
|
<DocsLayout {...baseOptions()} tree={pageTree}>
|
|
<Content path={path} markdownUrl={markdownUrl} />
|
|
</DocsLayout>
|
|
);
|
|
}
|