Add i18n to home sections, improve consent management and middleware asset handling

Co-authored-by: dennis <dennis@konkol.net>
This commit is contained in:
Cursor Agent
2026-01-12 15:57:28 +00:00
parent 6a4055500b
commit 683735cc63
11 changed files with 173 additions and 85 deletions

View File

@@ -20,6 +20,23 @@ function hasLocalePrefix(pathname: string): boolean {
export function middleware(request: NextRequest) {
const { pathname, search } = request.nextUrl;
// If a locale-prefixed request hits a public asset path (e.g. /de/images/me.jpg),
// redirect to the non-prefixed asset path.
if (hasLocalePrefix(pathname)) {
const rest = pathname.replace(/^\/(en|de)/, "") || "/";
if (rest.includes(".")) {
const responseUrl = request.nextUrl.clone();
responseUrl.pathname = rest;
const res = NextResponse.redirect(responseUrl);
return addHeaders(request, res);
}
}
// Do not locale-route public assets (anything with a dot), robots, sitemap, etc.
if (pathname.includes(".")) {
return addHeaders(request, NextResponse.next());
}
// Keep admin + APIs unlocalized for simplicity
const isAdminOrApi =
pathname.startsWith("/api/") ||
@@ -107,8 +124,7 @@ export const config = {
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico (favicon file)
* - any path containing a dot (public assets like /images/*.jpg, /robots.txt, /sitemap.xml, etc.)
*/
"/((?!api|_next/static|_next/image|favicon.ico|.*\\..*).*)",
"/((?!api|_next/static|_next/image|favicon.ico).*)",
],
};