Repository navigation
fix: scope multi-section routes on unversioned and baseUrl sites - #77
Merged
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
With several
docsDirsections,resolveDocumentUrlmatches each doc only against routes under its section'srouteBasePath. On an unversioned site, the empty version prefix built that scope as//other. No route matched, so every doc in a section whoserouteBasePathisn'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
/otherwhen unversioned,/<version>/otherwhen versioned.siteUrl) from each route before comparing it against version prefixes, routeBasePaths andblogRouteBasePath, 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 torouteBasePath.slug: "/") lookup uses the same join, so a root page in a versioned root section resolves to/<version>instead of an unmatched<version>.getSiteBasePathandstripSiteBasePathlive inutils.ts.generator.tsuses 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 totest:integration) covers:baseUrl: '/'baseUrl: '/sub/'baseUrl: '/sub/'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, andnpm testpasses.