feat(Docs): Implement Accept header for agents markdown requests (#43745)

This commit is contained in:
Jeremias Menichelli authored and GitHub committed 2026-03-13 13:32:40 +01:00
1 parent 97f10d2087
commit 41962e6bf5
1 file changed
+5 -2
+5 -2
View File
@@ -11,9 +11,12 @@ const GUIDES_PATH = `${BASE_PATH ?? ''}/guides`
export function middleware(request: NextRequest) {
const url = new URL(request.url)
const requestsMarkdown =
request.headers.get('Accept')?.includes('text/markdown') || url.pathname.endsWith('.md')
// Serve pre-generated .md files before the [[...slug]] page route can intercept them
if (url.pathname.startsWith(GUIDES_PATH + '/') && url.pathname.endsWith('.md')) {
const slug = url.pathname.slice(GUIDES_PATH.length + 1, -'.md'.length)
if (url.pathname.startsWith(GUIDES_PATH + '/') && requestsMarkdown) {
const slug = url.pathname.replace(`${GUIDES_PATH}/`, '').replace(/\.md$/, '')
const rewriteUrl = new URL(url)
rewriteUrl.pathname = `${BASE_PATH ?? ''}/api/guides-md/${slug}`
return NextResponse.rewrite(rewriteUrl)