mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-19 08:28:06 +02:00
fix(docs-site): add docs index redirect, test, and trim Accept media type
Redirect bare /docs to the introduction page with proper metadata resolution. Add a test for the redirect. Trim the media type in the Accept header parser so whitespace around semicolons does not break markdown content negotiation. Add a test script to package.json. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
e79caa8fb9
commit
b4a302edfa
4 changed files with 33 additions and 5 deletions
|
|
@ -5,15 +5,26 @@ import {
|
|||
DocsTitle,
|
||||
DocsDescription,
|
||||
} from "fumadocs-ui/page";
|
||||
import { notFound } from "next/navigation";
|
||||
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";
|
||||
|
||||
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("/") === "";
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
|
|
@ -35,14 +46,16 @@ export default async function Page(props: {
|
|||
}
|
||||
|
||||
export function generateStaticParams() {
|
||||
return source.generateParams();
|
||||
return [{ slug: [""] }, ...source.generateParams()];
|
||||
}
|
||||
|
||||
export async function generateMetadata(props: {
|
||||
params: Promise<{ slug?: string[] }>;
|
||||
}) {
|
||||
const params = await props.params;
|
||||
const page = source.getPage(params.slug);
|
||||
const page = source.getPage(
|
||||
isDocsIndex(params.slug) ? [...docsIndexSlug] : params.slug,
|
||||
);
|
||||
if (!page) notFound();
|
||||
|
||||
return {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue