From 36ea92e90b14bee85682c73cc4f7fd4e01cf1a67 Mon Sep 17 00:00:00 2001 From: Sarthak Agrawal Date: Sat, 26 Sep 2026 00:23:48 +0530 Subject: [PATCH] fix(landing): align Repo Unpack canonicals --- .../src/pages/unpack/[slug]/[section].astro | 2 +- apps/landing-page-astro/worker.mjs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/landing-page-astro/src/pages/unpack/[slug]/[section].astro b/apps/landing-page-astro/src/pages/unpack/[slug]/[section].astro index 6fed3000..3795e940 100644 --- a/apps/landing-page-astro/src/pages/unpack/[slug]/[section].astro +++ b/apps/landing-page-astro/src/pages/unpack/[slug]/[section].astro @@ -25,7 +25,7 @@ const { report, section, sectionKey, title } = Astro.props;
← {report.repo} diff --git a/apps/landing-page-astro/worker.mjs b/apps/landing-page-astro/worker.mjs index 13a52a3c..5a7bb3e5 100644 --- a/apps/landing-page-astro/worker.mjs +++ b/apps/landing-page-astro/worker.mjs @@ -378,6 +378,19 @@ export default { const url = new URL(request.url); const pathname = url.pathname; + // Older Repo Unpack canonicals used underscored section keys, while the + // generated routes use hyphens. Redirect only when the target exists. + const legacySection = + (request.method === 'GET' || request.method === 'HEAD') && + pathname.match(/^\/unpack\/[^/]+\/([^/]*_[^/]*)$/); + if (legacySection) { + const target = new URL(url); + target.pathname = + pathname.slice(0, -legacySection[1].length) + legacySection[1].replaceAll('_', '-'); + const targetResponse = await env.ASSETS.fetch(new Request(target, { method: 'HEAD' })); + if (targetResponse.ok) return Response.redirect(target, 301); + } + // /openapi.json — serve the spec directly. if (pathname === '/openapi.json' || pathname === '/openapi.yaml') { return serveOpenApiSpec();