Files
TREK/client/src/help/headingSlug.ts
T
Maurice 5584d287a9 refactor(help): register a screen from one description, and fix the doc links
Every context file carried its own copy of the same little guide factory and
the same context literal. Thirteen screens of a trip would have made thirteen
copies of it, which is both the duplication a quality gate counts and the
hand-mirrored state the repository asks us not to keep, so the shape moves into
defineScreen and a context file becomes data: ids, counts, docs, cross-links.

Four doc links never resolved. Trip-Planner and Sharing-and-Collaboration are
not wiki pages (Trip-Planner-Overview and Trip-Members-and-Sharing are), the
places import anchor is importing-multiple-places, and the offline anchor was
written in GitHub's slug, which is not the one the in-app reader produces.
Nothing caught them, so the registry test now checks every slug and every
anchor against wiki/, with the heading slug itself lifted out of HelpPage so
the reader and the test cannot drift apart.
2026-09-24 14:05:42 +02:00

18 lines
671 B
TypeScript

/**
* The anchor a wiki heading gets when TREK renders it.
*
* Lowercase, drop everything that is not a word character, whitespace or a
* hyphen, trim, and turn each run of whitespace into one hyphen. The help
* center links into the wiki with `#<anchor>` (`docsRoute`), so a guide's
* anchor has to be the slug this produces, not the one another renderer would.
* It lives on its own so the reader and the test that guards the links agree
* by construction instead of by two copies of the same regexes.
*/
export function headingSlug(text: string): string {
return text
.toLowerCase()
.replace(/[^\w\s-]/g, '')
.trim()
.replace(/\s+/g, '-')
}