mirror of
https://wget.la/https://github.com/leookun/cursor-byok
synced 2026-10-06 05:12:03 +08:00
feat(docs): enhance documentation site with internationalization and layout updates
- Updated the demo API to support locale-based content rendering. - Refactored the main layout to accommodate language-specific metadata and routing. - Introduced new components for blog and documentation pages, ensuring proper language handling. - Added styles for improved UI consistency across different sections. - Removed deprecated layout files and streamlined the structure for better maintainability.
This commit is contained in:
+30
-9
@@ -1,5 +1,7 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { NextRequest, NextResponse, type NextFetchEvent } from 'next/server';
|
||||
import { isMarkdownPreferred, rewritePath } from 'fumadocs-core/negotiation';
|
||||
import { createI18nMiddleware } from 'fumadocs-core/i18n/middleware';
|
||||
import { i18n, type Language } from '@/lib/i18n';
|
||||
import { docsContentRoute, docsRoute } from '@/lib/shared';
|
||||
|
||||
const { rewrite: rewriteDocs } = rewritePath(
|
||||
@@ -11,22 +13,41 @@ const { rewrite: rewriteSuffix } = rewritePath(
|
||||
`${docsContentRoute}{/*path}/content.md`,
|
||||
);
|
||||
|
||||
export default function proxy(request: NextRequest) {
|
||||
const result = rewriteSuffix(request.nextUrl.pathname);
|
||||
if (result) {
|
||||
return NextResponse.rewrite(new URL(result, request.nextUrl));
|
||||
const i18nMiddleware = createI18nMiddleware(i18n);
|
||||
|
||||
/** Split the locale prefix (if any) from a pathname. */
|
||||
function splitLocale(pathname: string): { locale: Language; rest: string } {
|
||||
for (const lang of i18n.languages) {
|
||||
if (pathname === `/${lang}`) return { locale: lang, rest: '/' };
|
||||
if (pathname.startsWith(`/${lang}/`)) {
|
||||
return { locale: lang, rest: pathname.slice(lang.length + 1) };
|
||||
}
|
||||
}
|
||||
return { locale: i18n.defaultLanguage, rest: pathname };
|
||||
}
|
||||
|
||||
export default function proxy(request: NextRequest, event: NextFetchEvent) {
|
||||
const { locale, rest } = splitLocale(request.nextUrl.pathname);
|
||||
|
||||
const suffixTarget = rewriteSuffix(rest);
|
||||
if (suffixTarget) {
|
||||
return NextResponse.rewrite(new URL(`/${locale}${suffixTarget}`, request.nextUrl));
|
||||
}
|
||||
|
||||
if (isMarkdownPreferred(request)) {
|
||||
const result = rewriteDocs(request.nextUrl.pathname);
|
||||
const target = rewriteDocs(rest);
|
||||
|
||||
if (result) {
|
||||
return NextResponse.rewrite(new URL(result, request.nextUrl), {
|
||||
if (target) {
|
||||
return NextResponse.rewrite(new URL(`/${locale}${target}`, request.nextUrl), {
|
||||
// this URL has two representations, selected by `Accept`
|
||||
headers: { Vary: 'Accept' },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.next();
|
||||
return i18nMiddleware(request, event);
|
||||
}
|
||||
|
||||
export const config = {
|
||||
matcher: ['/((?!api|_next|favicon.ico|images/|product-demo/|llms\\.txt|llms-full\\.txt).*)'],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user