Problem
lib/helpers/guides.js → titleFromPath renders guide filenames verbatim. Projects that prefix guides with a numeric order key (e.g. 00-welcome.md, 01-api-access.md) so the Scalar sidebar stays in the right order end up with ugly titles in the rendered output:
00-welcome.md → 00 Welcome
01-api-access.md → 01 Api Access
02-scraping.md → 02 Scraping
The number is load-bearing for the sort (the loader uses a.title.localeCompare(b.title)), but readers should never see it.
Real-world example: https://github.com/comes-io/trawl_node/pull/(TBD) — trawl_node now renumbers its 5 public guides to get explicit ordering, and lives with "00 Welcome" / "01 Api Access" titles in the sidebar.
Proposal
In titleFromPath, strip a leading ^\d+[-_] from the basename before title-casing. Keep the original filename available for sorting.
const titleFromPath = (filePath) => {
const base = path.basename(String(filePath), path.extname(String(filePath)));
const stripped = base.replace(/^\d+[-_]/, '');
return stripped
.split(/[-_\s]+/)
.filter(Boolean)
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
.join(' ');
};
Sorting currently happens on the rendered title — which would collapse the intended order if two guides differ only by their numeric prefix. The sort key should be derived from the filename instead (or from the raw basename) so 00-welcome sorts before 01-api-access regardless of their rendered titles.
Alternative
Support an explicit order: frontmatter (YAML or <!-- order: 10 -->) in each guide. More expressive but heavier to implement. The numeric-prefix convention is dead simple and already works — it just needs the title-stripping fix.
Scope
lib/helpers/guides.js only
- Add unit tests in
modules/core/tests/core.unit.tests.js for both titleFromPath with numeric prefixes and loadGuides sort order
- No downstream migration needed — existing projects without prefixes are unaffected
Problem
lib/helpers/guides.js→titleFromPathrenders guide filenames verbatim. Projects that prefix guides with a numeric order key (e.g.00-welcome.md,01-api-access.md) so the Scalar sidebar stays in the right order end up with ugly titles in the rendered output:00-welcome.md→ 00 Welcome01-api-access.md→ 01 Api Access02-scraping.md→ 02 ScrapingThe number is load-bearing for the sort (the loader uses
a.title.localeCompare(b.title)), but readers should never see it.Real-world example: https://github.com/comes-io/trawl_node/pull/(TBD) — trawl_node now renumbers its 5 public guides to get explicit ordering, and lives with "00 Welcome" / "01 Api Access" titles in the sidebar.
Proposal
In
titleFromPath, strip a leading^\d+[-_]from the basename before title-casing. Keep the original filename available for sorting.Sorting currently happens on the rendered title — which would collapse the intended order if two guides differ only by their numeric prefix. The sort key should be derived from the filename instead (or from the raw basename) so
00-welcomesorts before01-api-accessregardless of their rendered titles.Alternative
Support an explicit
order:frontmatter (YAML or<!-- order: 10 -->) in each guide. More expressive but heavier to implement. The numeric-prefix convention is dead simple and already works — it just needs the title-stripping fix.Scope
lib/helpers/guides.jsonlymodules/core/tests/core.unit.tests.jsfor bothtitleFromPathwith numeric prefixes andloadGuidessort order