feat: add middleware support for .md file rewrites
This commit is contained in:
@@ -36,6 +36,13 @@ function negotiate(accept: string): Negotiated {
|
||||
export function middleware(request: NextRequest) {
|
||||
const accept = request.headers.get('accept') ?? '';
|
||||
const { pathname } = request.nextUrl;
|
||||
|
||||
if (pathname.endsWith('.md')) {
|
||||
const headers = new Headers(request.headers);
|
||||
headers.set('x-md-path', pathname.slice(0, -3));
|
||||
return NextResponse.rewrite(new URL('/api/md', request.url), { request: { headers } });
|
||||
}
|
||||
|
||||
const result = negotiate(accept);
|
||||
|
||||
if (result === 'none') {
|
||||
|
||||
@@ -36,6 +36,12 @@ function negotiate(accept: string): Negotiated {
|
||||
export function middleware(request: NextRequest) {
|
||||
const accept = request.headers.get('accept') ?? '';
|
||||
const { pathname } = request.nextUrl;
|
||||
|
||||
if (pathname.endsWith('.md')) {
|
||||
const rewriteUrl = new URL(`/llms.mdx${pathname.slice(0, -3)}`, request.url);
|
||||
return NextResponse.rewrite(rewriteUrl);
|
||||
}
|
||||
|
||||
const result = negotiate(accept);
|
||||
|
||||
if (result === 'none') {
|
||||
|
||||
Reference in New Issue
Block a user