Add i18n to home sections, improve consent management and middleware asset handling
Co-authored-by: dennis <dennis@konkol.net>
This commit is contained in:
@@ -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).*)",
|
||||
],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user