Skip to content

fix: scope multi-section routes on unversioned and baseUrl sites - #77

Merged
rachfop merged 1 commit into
rachfop:mainfrom
ersanne:fix/multi-section-route-scoping
Oct 2, 2026
Merged

rachfop merged 1 commit into
rachfop:mainfrom
ersanne:fix/multi-section-route-scoping

Conversation

@ersanne

@ersanne ersanne commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Problem

With several docsDir sections, resolveDocumentUrl matches each doc only against routes under its section's routeBasePath. On an unversioned site, the empty version prefix built that scope as //other. No route matched, so every doc in a section whose routeBasePath isn't / fell back to a file-name URL. For README/index files that URL names a page that doesn't exist.

With other-docs/README.md and other-docs/guide/README.md, llms.txt lists:

- [Other](https://example.com/other/README)
- [Guide](https://example.com/other/guide/README)

Expected:

- [Other](https://example.com/other/)
- [Guide](https://example.com/other/guide/)

Fix

  • Build the section scope from its non-empty parts: /other when unversioned, /<version>/other when versioned.
  • Strip the site's baseUrl (derived from siteUrl) from each route before comparing it against version prefixes, routeBasePaths and blogRouteBasePath, which are relative to the baseUrl. Section, version and blog scoping now work on sites served from a subpath (baseUrl: '/sub/') without adding the baseUrl to routeBasePath.
  • The root-slug (slug: "/") lookup uses the same join, so a root page in a versioned root section resolves to /<version> instead of an unmatched <version>.
  • getSiteBasePath and stripSiteBasePath live in utils.ts. generator.ts uses them in place of its own baseUrl stripping when deriving output file paths; the resulting paths are unchanged.

Tests

tests/test-multi-section-route-scoping.js (added to test:integration) covers:

  • two unversioned sections with baseUrl: '/'
  • the same site with baseUrl: '/sub/'
  • a versioned site with baseUrl: '/sub/'
  • a blog post and a doc that share a slug, with baseUrl: '/sub/'

The first three fail on main. The blog case fails when baseUrl stripping is removed from section scoping. All four pass with this change, and npm test passes.

With several docsDir sections, resolveDocumentUrl matches each doc only
against routes under its section's routeBasePath. On an unversioned site
the empty version prefix built that scope as "//other", so no route
matched and every doc in the section fell back to a file-name URL. For
README/index files that URL names a page that doesn't exist
(/other/README instead of /other/).

Build the scope from its non-empty parts, which gives /other unversioned
and /<version>/other versioned.

Version prefixes, routeBasePaths and blogRouteBasePath are relative to
the site's baseUrl, but Docusaurus's routesPaths include it. Strip the
baseUrl, derived from siteUrl, from each route before comparing. Section,
version and blog scoping then work on sites served from a subpath
without adding the baseUrl to routeBasePath.

The root-slug (slug: "/") lookup uses the same join, so a root page in a
versioned root section resolves to /<version> instead of an unmatched
"<version>".

getSiteBasePath and stripSiteBasePath live in utils.ts, and generator.ts
uses them for its own baseUrl stripping when deriving output file paths.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants