From f11e3855d98e2a7d8540aa000b42b0d78cd538c6 Mon Sep 17 00:00:00 2001 From: Hyan Mandian <5044101+hyanmandian@users.noreply.github.com> Date: Tue, 13 Oct 2026 19:00:46 -0300 Subject: [PATCH 1/2] Old JavaScript docs links go to the utility they pointed at MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The docsify site kept the section in the query string (/utilities?id=isvalidcpf, /pt-br/utilities?id=cep-e-endereço). _redirects sends those to the JavaScript library's page with the ?id= kept, and Google counted 137 of them as alternates of that one page. The library's page now reads the id and replaces the location with the utility's page (and the function's section), from /legacy-ids.json: the JavaScript symbols from the last validator run, the utilities' titles and ids, and the old page's other section headings. An unknown id stays on the library's page. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01RaUEDkvXY8rVWTJG2GKfhu --- site/src/app/legacy-ids.json/route.ts | 9 ++++ site/src/components/pages/lib.tsx | 8 ++++ site/src/lib/legacy-ids.ts | 64 +++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 site/src/app/legacy-ids.json/route.ts create mode 100644 site/src/lib/legacy-ids.ts diff --git a/site/src/app/legacy-ids.json/route.ts b/site/src/app/legacy-ids.json/route.ts new file mode 100644 index 0000000..91519cf --- /dev/null +++ b/site/src/app/legacy-ids.json/route.ts @@ -0,0 +1,9 @@ +// /legacy-ids.json: where each anchor of the old JavaScript docs is now (see lib/legacy-ids.ts). +// Only the JavaScript library's page reads it, and only when its URL has an ?id=. +import { legacyIds } from '@/lib/legacy-ids'; + +export const dynamic = 'force-static'; + +export function GET() { + return Response.json(legacyIds()); +} diff --git a/site/src/components/pages/lib.tsx b/site/src/components/pages/lib.tsx index b69eda8..a2dcad8 100644 --- a/site/src/components/pages/lib.tsx +++ b/site/src/components/pages/lib.tsx @@ -31,6 +31,13 @@ const show = (v: unknown) => (v === undefined || v === null ? 'null' : JSON.stri const LONG = 15; const GROUPS = ['failing', 'signature', 'missing'] as const; +/** + * The old JavaScript docs' links (/utilities?id=isvalidcpf) arrive here through public/_redirects + * with their ?id= kept: this sends each to its utility's page. A redirect rule cannot read the query. + */ +const legacyRedirect = (locale: Locale) => + `(function(){var id=new URLSearchParams(location.search).get('id');if(!id)return;fetch('${base}/legacy-ids.json').then(function(r){return r.json()}).then(function(m){var h=m[${JSON.stringify(locale)}][id.toLowerCase()];if(h)location.replace('${base}${prefixOf(locale)}'+h)}).catch(function(){})})()`; + export async function LibPage({ locale, id }: { locale: Locale; id: string }) { const libs = loadLibs(); const lib = libs.find((l: any) => l.id === id); @@ -95,6 +102,7 @@ export async function LibPage({ locale, id }: { locale: Locale; id: string }) { return ( + {lib.id === 'javascript' &&