Skip to content

fix: anchor links broken when trailing slash is missing#270

Merged
marc0olo merged 1 commit into
mainfrom
infra/fix-anchor-links-without-trailing-slash
May 21, 2026
Merged

fix: anchor links broken when trailing slash is missing#270
marc0olo merged 1 commit into
mainfrom
infra/fix-anchor-links-without-trailing-slash

Conversation

@marc0olo
Copy link
Copy Markdown
Member

Summary

  • Fixes anchor links on all doc pages when accessed without a trailing slash (e.g. /references/resource-limits instead of /references/resource-limits/)
  • Root cause: rehype-rewrite-links.mjs was emitting relative hrefs (../foo/#anchor). Browser relative URL resolution depends on whether the current URL ends with a slash, causing the wrong target on non-trailing-slash URLs
  • Fix: the plugin now emits root-relative absolute hrefs (e.g. /references/ic-interface-spec/canister-interface/#system-api-module) by resolving each .md link against the current file's position in the docs tree — these are unaffected by the browser URL form
  • Also removes the now-unnecessary isIndexPage distinction (index and non-index pages are handled uniformly with absolute paths)
  • Affects all 118+ pages that use relative .md links

Closes #269

Sync recommendation

hand-written

…ut trailing slash

Relative hrefs like `../ic-interface-spec/canister-interface/#system-api-module`
resolve differently depending on whether the browser URL ends with a slash:

  /references/resource-limits/  + ../foo/ → /references/foo/  (correct)
  /references/resource-limits   + ../foo/ → /foo/             (wrong)

The plugin now computes an absolute root-relative path by resolving the
.md link against the current file's position in the docs tree. The generated
href (e.g. /references/ic-interface-spec/canister-interface/#system-api-module)
is not affected by the browser URL at all, so anchor links work on both the
trailing-slash and non-trailing-slash forms of every page.

Closes #269
@marc0olo marc0olo requested a review from a team as a code owner May 21, 2026 14:49
@marc0olo marc0olo merged commit 3b7d3f0 into main May 21, 2026
7 checks passed
@marc0olo marc0olo deleted the infra/fix-anchor-links-without-trailing-slash branch May 21, 2026 14:57
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.

anchor link not working correctly when trailing / is missing on the resource-limits page

2 participants