docs: serve markdown to agents (#13915)

This commit is contained in:
Shahed Nasser authored and GitHub committed 2025-10-30 17:59:22 +02:00
1 parent 66bbe39a8e
commit b1b6960147
11 files changed
+173 -75

No files matched your search

@@ -1,5 +1,5 @@
import { getCleanMd } from "docs-utils"
import { existsSync } from "fs"
import { existsSync, readFileSync } from "fs"
import { unstable_cache } from "next/cache"
import { notFound } from "next/navigation"
import { NextRequest, NextResponse } from "next/server"
@@ -16,7 +16,21 @@ type Params = {
}
export async function GET(req: NextRequest, { params }: Params) {
const { slug } = await params
const { slug = ["/"] } = await params
if (slug[0] === "/") {
const llmsFile = readFileSync(
path.join(process.cwd(), "public", "llms.txt"),
"utf-8"
)
return new NextResponse(llmsFile, {
headers: {
"Content-Type": "text/markdown",
},
status: 200,
})
}
// keep this so that Vercel keeps the files in deployment
const basePath = path.join(process.cwd(), "app")
-13
View File
@@ -1,13 +0,0 @@
import { NextResponse } from "next/server"
import type { NextRequest } from "next/server"
export function middleware(request: NextRequest) {
const path = request.nextUrl.pathname.replace("/index.html.md", "")
return NextResponse.rewrite(
new URL(`/md-content${path.replace("/index.html.md", "")}`, request.url)
)
}
export const config = {
matcher: "/((?!resources|api|ui|user-guide|cloud).*)index.html.md",
}
+29
View File
@@ -115,6 +115,35 @@ const nextConfig = {
transpilePackages: ["docs-ui"],
async rewrites() {
return {
beforeFiles: [
{
source:
"/:path((?!resources|api|ui|user-guide|cloud).*)index.html.md",
destination: "/md-content/:path*",
},
{
source: "/:path*",
has: [
{
type: "header",
key: "Accept",
value: "text/markdown",
},
],
destination: "/md-content/:path*",
},
{
source: "/:path*",
has: [
{
type: "header",
key: "Accept",
value: "text/plain",
},
],
destination: "/md-content/:path*",
},
],
fallback: [
{
source: "/resources",