INNER CODE UNIT · TypeScript
maybeRedirectToCanonicalModelSlug
Ammaar-Alam/minebench · middleware.ts:108
function maybeRedirectToCanonicalModelSlug(req: NextRequest) {
const { pathname } = req.nextUrl;
const match = pathname.match(/^\/leaderboard\/([^/]+)$/);
if (!match) return null;
const rawKey = safeDecodeURIComponent(match[1]);
if (!rawKey) return null;
const canonicalSlug = resolveModelSlug(rawKey);
if (canonicalSlug && canonicalSlug !== rawKey) {
const nextUrl = req.nextUrl.clone();
nextUrl.pathname = `/leaderboard/${encodeURIComponent(canonicalSlug)}`;
return NextResponse.redirect(nextUrl, 308);
}
return null;
}
function isModelDetailPath(pathname: string): boolean {