Skip to content

The Open Standard for Generative UI

Serve docs as Markdown when requested (#782)

Zahle Khan4aea658ed4e8
diff --git a/docs/proxy.ts b/docs/proxy.ts
new file mode 100644
index 000000000..e1bd76019
--- /dev/null
+++ b/docs/proxy.ts
@@ -0,0 +1,16 @@
+import { isMarkdownPreferred, rewritePath } from "fumadocs-core/negotiation";
+import { type NextRequest, NextResponse } from "next/server";
+
+const { rewrite: rewriteLLM } = rewritePath("/docs{/*path}", "/llms.mdx/docs{/*path}");
+
+export default function proxy(request: NextRequest) {
+ if (isMarkdownPreferred(request)) {
+ const markdownPath = rewriteLLM(request.nextUrl.pathname);
+
+ if (markdownPath) {
+ return NextResponse.rewrite(new URL(markdownPath, request.nextUrl));
+ }
+ }
+
+ return NextResponse.next();
+}