From 03bd434333810125c3a93b71c288cab651dcae9b Mon Sep 17 00:00:00 2001 From: Dimitrie Hoekstra Date: Wed, 2 Sep 2026 19:37:42 +0200 Subject: [PATCH] fix: hyphenate each space in integration README heading slugs githubSlugify collapsed runs of whitespace into a single hyphen. GitHub strips the punctuation first and then hyphenates the remaining spaces one at a time, so a heading with punctuation between two words keeps the space on either side of it and lands a double hyphen. node-red-contrib-counter's "Bugs / Feature request" is #bugs--feature-request on GitHub, its own table of contents links to that, and we generated #bugs-feature-request, so the link pointed at an id that did not exist. That is the bad anchor failing the link checker on main, and with it every table-of-contents entry a README author wrote against GitHub for a heading with punctuation in it. Headings whose words are separated by single spaces slug identically either way, which is why one anchor broke rather than hundreds. The checker's own --check-anchors run over the built integration pages is the regression guard; githubSlugify is private to a .ts util and the test script only globs .mjs libs, so there is nowhere to unit test it without restructuring. --- nuxt/server/utils/integrations-enrich.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/nuxt/server/utils/integrations-enrich.ts b/nuxt/server/utils/integrations-enrich.ts index 972c29e482..b15c286bad 100644 --- a/nuxt/server/utils/integrations-enrich.ts +++ b/nuxt/server/utils/integrations-enrich.ts @@ -24,13 +24,22 @@ const GITHUB_HEADERS = { // Mirrors GitHub's own heading slugger so anchors written against a README's // GitHub-rendered preview (e.g. `#egm-optional` for "## EGM (optional)") keep resolving here. +// +// One space per hyphen, not one per run of them. GitHub strips the punctuation first and +// hyphenates whatever spaces are left, each on its own, so a heading with punctuation +// between two words keeps the space on both sides of it and lands a double hyphen: +// "Bugs / Feature request" is `#bugs--feature-request` there. Collapsing runs with \s+ +// gave `#bugs-feature-request` and every table-of-contents link a README author wrote +// against GitHub for such a heading pointed at an id that did not exist. Headings whose +// words are separated by a single space are identical either way, which is why only the +// punctuated ones broke. function githubSlugify (heading: string): string { return encodeURIComponent( heading .trim() .toLowerCase() .replace(/[^\w一-龥\- ]/g, '') - .replace(/\s+/g, '-') + .replace(/\s/g, '-') ) }