mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-07 07:55:13 +02:00
The three page-level buttons (Copy MD, View MD, Copy MDX) were broken because the fetch URL missed the /ktx basePath. Replace with a single "Copy as Markdown" button that strips frontmatter from the MDX source already available client-side — no fetch needed. Drop the .md link since agents discover markdown URLs through llms.txt and content negotiation. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
85 lines
2.4 KiB
TypeScript
85 lines
2.4 KiB
TypeScript
import { source } from "@/lib/source";
|
|
import {
|
|
DocsPage,
|
|
DocsBody,
|
|
DocsTitle,
|
|
DocsDescription,
|
|
} from "fumadocs-ui/page";
|
|
import { notFound, redirect } from "next/navigation";
|
|
import defaultMdxComponents from "fumadocs-ui/mdx";
|
|
import { CodeBlock } from "@/components/code-block";
|
|
import { DocsPageActions } from "@/components/docs-page-actions";
|
|
import { readDocsPageMarkdown } from "@/lib/docs-markdown";
|
|
|
|
const docsIndexPath = "/docs/getting-started/introduction";
|
|
const docsIndexSlug = ["getting-started", "introduction"] as const;
|
|
|
|
function isDocsIndex(slug: string[] | undefined) {
|
|
return slug === undefined || slug.length === 0 || slug.join("/") === "";
|
|
}
|
|
|
|
function isHeroPage(slug: string[] | undefined) {
|
|
return slug?.join("/") === "getting-started/introduction";
|
|
}
|
|
|
|
export default async function Page(props: {
|
|
params: Promise<{ slug?: string[] }>;
|
|
}) {
|
|
const params = await props.params;
|
|
if (isDocsIndex(params.slug)) {
|
|
redirect(docsIndexPath);
|
|
}
|
|
|
|
const page = source.getPage(params.slug);
|
|
if (!page) notFound();
|
|
|
|
const MDX = page.data.body;
|
|
const mdxSource = await readDocsPageMarkdown(page.slugs);
|
|
|
|
const hero = isHeroPage(params.slug);
|
|
|
|
return (
|
|
<DocsPage
|
|
toc={page.data.toc}
|
|
className="!mx-0 min-w-0 justify-self-start md:!mx-auto"
|
|
style={{
|
|
width: "calc(100vw - 2rem)",
|
|
maxWidth: "900px",
|
|
}}
|
|
>
|
|
{!hero && (
|
|
<>
|
|
<div className="flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between sm:gap-4">
|
|
<DocsTitle>{page.data.title}</DocsTitle>
|
|
<DocsPageActions mdxSource={mdxSource} />
|
|
</div>
|
|
<DocsDescription className="wrap-anywhere">
|
|
{page.data.description}
|
|
</DocsDescription>
|
|
</>
|
|
)}
|
|
<DocsBody className="min-w-0 max-w-full wrap-anywhere">
|
|
<MDX components={{ ...defaultMdxComponents, pre: CodeBlock }} />
|
|
</DocsBody>
|
|
</DocsPage>
|
|
);
|
|
}
|
|
|
|
export function generateStaticParams() {
|
|
return [{ slug: [""] }, ...source.generateParams()];
|
|
}
|
|
|
|
export async function generateMetadata(props: {
|
|
params: Promise<{ slug?: string[] }>;
|
|
}) {
|
|
const params = await props.params;
|
|
const page = source.getPage(
|
|
isDocsIndex(params.slug) ? [...docsIndexSlug] : params.slug,
|
|
);
|
|
if (!page) notFound();
|
|
|
|
return {
|
|
title: page.data.title,
|
|
description: page.data.description,
|
|
};
|
|
}
|