mirror of
https://github.com/vercel/components.build.git
synced 2026-09-14 20:06:39 +08:00
35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
import { createI18nMiddleware } from "fumadocs-core/i18n/middleware";
|
|
import { isMarkdownPreferred, rewritePath } from "fumadocs-core/negotiation";
|
|
import {
|
|
type NextFetchEvent,
|
|
type NextRequest,
|
|
NextResponse,
|
|
} from "next/server";
|
|
import { i18n } from "@/lib/geistdocs/i18n";
|
|
|
|
const { rewrite: rewriteLLM } = rewritePath("/*path", "/llms.mdx/*path");
|
|
|
|
const internationalizer = createI18nMiddleware(i18n);
|
|
|
|
const proxy = (request: NextRequest, context: NextFetchEvent) => {
|
|
// First, handle Markdown preference rewrites
|
|
if (isMarkdownPreferred(request)) {
|
|
const result = rewriteLLM(request.nextUrl.pathname);
|
|
if (result) {
|
|
return NextResponse.rewrite(new URL(result, request.nextUrl));
|
|
}
|
|
}
|
|
|
|
// Fallback to i18n middleware
|
|
return internationalizer(request, context);
|
|
};
|
|
|
|
export const config = {
|
|
// Matcher ignoring `/_next/`, `/api/`, static assets, favicon, sitemap, robots, etc.
|
|
matcher: [
|
|
"/((?!api|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)",
|
|
],
|
|
};
|
|
|
|
export default proxy;
|