mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-29 04:14:54 +00:00
46 lines
1.6 KiB
TypeScript
46 lines
1.6 KiB
TypeScript
import type { Route } from './+types/docs';
|
|
import { DocsLayout } from '@hanzo/docs-ui/layouts/docs';
|
|
import { DocsBody, DocsDescription, DocsPage, DocsTitle } from '@hanzo/docs-ui/layouts/docs/page';
|
|
import { source } from '@/lib/source';
|
|
import browserCollections from 'collections/browser';
|
|
import { baseOptions } from '@/lib/layout.shared';
|
|
import { useFumadocsLoader } from '@hanzo/docs-core/source/client';
|
|
import { useMDXComponents } from '@/components/mdx';
|
|
|
|
export async function loader({ params }: Route.LoaderArgs) {
|
|
const slugs = params['*'].split('/').filter((v) => v.length > 0);
|
|
const page = source.getPage(slugs, params.lang);
|
|
if (!page) throw new Response('Not found', { status: 404 });
|
|
|
|
return {
|
|
path: page.path,
|
|
pageTree: await source.serializePageTree(source.getPageTree(params.lang)),
|
|
};
|
|
}
|
|
|
|
const clientLoader = browserCollections.docs.createClientLoader({
|
|
component({ toc, frontmatter, default: Mdx }) {
|
|
return (
|
|
<DocsPage toc={toc}>
|
|
<title>{frontmatter.title}</title>
|
|
<meta name="description" content={frontmatter.description} />
|
|
<DocsTitle>{frontmatter.title}</DocsTitle>
|
|
<DocsDescription>{frontmatter.description}</DocsDescription>
|
|
<DocsBody>
|
|
<Mdx components={useMDXComponents()} />
|
|
</DocsBody>
|
|
</DocsPage>
|
|
);
|
|
},
|
|
});
|
|
|
|
export default function Page({ loaderData, params }: Route.ComponentProps) {
|
|
const { pageTree } = useFumadocsLoader(loaderData);
|
|
|
|
return (
|
|
<DocsLayout {...baseOptions(params.lang)} tree={pageTree}>
|
|
{clientLoader.useContent(loaderData.path)}
|
|
</DocsLayout>
|
|
);
|
|
}
|