mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
feat(Docs): Implement Accept header for agents markdown requests (#43745)
This commit is contained in:
1 parent
97f10d2087
commit
41962e6bf5
1 file changed
+5
-2
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user