docs: support markdown response for AI (#5105)

This commit is contained in:
Saatvik Arya
2025-10-06 06:01:32 +05:30
committed by GitHub
parent 935c9be751
commit 9da8c8bf89
5 changed files with 814 additions and 63 deletions

20
docs/middleware.ts Normal file
View File

@@ -0,0 +1,20 @@
import { NextRequest, NextResponse } from "next/server";
import { isMarkdownPreferred, rewritePath } from "fumadocs-core/negotiation";
const { rewrite: rewriteLLM } = rewritePath("/docs/*path", "/llms.txt/*path");
export function middleware(request: NextRequest) {
if (isMarkdownPreferred(request)) {
const result = rewriteLLM(request.nextUrl.pathname);
if (result) {
return NextResponse.rewrite(new URL(result, request.nextUrl));
}
}
return NextResponse.next();
}
export const config = {
matcher: "/docs/:path*",
};