Skip to content

fix: resolve page URLs and markdown paths the way Docusaurus routes them - #87

Merged
rachfop merged 2 commits into
mainfrom
fix/url-resolution
Oct 2, 2026
Merged

rachfop merged 2 commits into
mainfrom
fix/url-resolution

Conversation

@rachfop

@rachfop rachfop commented Oct 2, 2026

Copy link
Copy Markdown
Owner

Page URLs and generated markdown paths could point at the wrong page or 404:

  • A docs page could take a standalone page's or blog post's route (docs/about.md resolved to /about). Docs files never match blog routes, and a single section prefers routes under its routeBasePath.
  • Date-prefixed blog posts linked to /blog/2024-01-01-hello; they now resolve to Docusaurus's /blog/2024/01/01/hello.
  • An index file at a section root could match an unrelated route (/blog/tags/docs).
  • With baseUrl equal to the first route segment (/docs/), generated .md links dropped the baseUrl.
  • Slugs: an index file's id took another page's URL, a nested absolute slug dropped docs/ from the .md path, and relative slugs failed under number-prefixed folders and on index files.
  • 02-api/02-api.md didn't resolve to /docs/api.
  • Routes with spaces were emitted unencoded, and .md files were written with percent-encoded names on disk.
  • Files inside _-prefixed directories were listed as pages; Docusaurus excludes them.
  • A custom heading id (# Title {#id}) stayed in the title and made the heading appear twice.
  • pathTransformation.ignorePaths missed a repeated segment.

tests/test-url-resolution.js covers each case. Two existing expectations change to match Docusaurus: an absolute slug's .md file lands under docs/, and link URLs are percent-encoded per segment. The docs site build output is unchanged. On a 3,461-page docs site, with and without its 6,728 real routes, the only difference is that pages under docs/_includes/ are no longer listed.

- Docs files match routes under their section's routeBasePath first and
  never match blog routes; blog files match blog routes only.
- Date-prefixed blog posts follow Docusaurus's YYYY/MM/DD route convention.
- A section-root index links its section's root route.
- Paths relative to the baseUrl always get it prepended, so a baseUrl equal
  to the route base is kept in markdown and fallback links.
- Frontmatter slug and id resolve like Docusaurus getSlug: absolute slugs
  join the route base, relative slugs and ids join the number-prefix-
  stripped file directory, and index files ignore id. Markdown files for
  route-resolved pages take their path from the route.
- A number-prefixed file named after its folder matches the stripped route.
- Links are percent-encoded per segment and markdown files are written
  under decoded names.
- Files in _-prefixed directories are not listed as pages.
- A trailing {#id} is dropped from heading titles and duplicate detection.
- pathTransformation removes adjacent duplicate segments and adds no
  trailing slash to an empty path.
…test

The small-fixes test was written against the old blog URL (/blog/2024-01-01-post). With date-prefixed posts resolved like Docusaurus, the URL is /blog/2024/01/01/post.
@rachfop
rachfop merged commit 412fc0a into main Oct 2, 2026
5 checks passed
@rachfop
rachfop deleted the fix/url-resolution branch October 2, 2026 23:08
rachfop added a commit that referenced this pull request Oct 2, 2026
…hem (#87)

* fix: resolve page URLs and markdown paths the way Docusaurus routes them

- Docs files match routes under their section's routeBasePath first and
  never match blog routes; blog files match blog routes only.
- Date-prefixed blog posts follow Docusaurus's YYYY/MM/DD route convention.
- A section-root index links its section's root route.
- Paths relative to the baseUrl always get it prepended, so a baseUrl equal
  to the route base is kept in markdown and fallback links.
- Frontmatter slug and id resolve like Docusaurus getSlug: absolute slugs
  join the route base, relative slugs and ids join the number-prefix-
  stripped file directory, and index files ignore id. Markdown files for
  route-resolved pages take their path from the route.
- A number-prefixed file named after its folder matches the stripped route.
- Links are percent-encoded per segment and markdown files are written
  under decoded names.
- Files in _-prefixed directories are not listed as pages.
- A trailing {#id} is dropped from heading titles and duplicate detection.
- pathTransformation removes adjacent duplicate segments and adds no
  trailing slash to an empty path.

* test: expect Docusaurus date paths for blog posts in the small-fixes test

The small-fixes test was written against the old blog URL (/blog/2024-01-01-post). With date-prefixed posts resolved like Docusaurus, the URL is /blog/2024/01/01/post.
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.

1 participant