Skip to content

Fix #3034: TOC highlighting on hosts with pretty URLs#3038

Closed
cobyfrombrooklyn-bot wants to merge 1 commit into
rust-lang:masterfrom
cobyfrombrooklyn-bot:fix-issue-3034
Closed

Fix #3034: TOC highlighting on hosts with pretty URLs#3038
cobyfrombrooklyn-bot wants to merge 1 commit into
rust-lang:masterfrom
cobyfrombrooklyn-bot:fix-issue-3034

Conversation

@cobyfrombrooklyn-bot
Copy link
Copy Markdown

Problem

When a hosting service (like Cloudflare Pages) strips .html from URLs ("pretty URLs"), the TOC sidebar highlighting breaks. The current page URL no longer ends in .html, but the TOC link hrefs still do, so the comparison link.href === current_page never matches.

Fix

Added a normalizeUrl() function in the TOC initialization JS that strips .html suffixes (and normalizes /index.html to /) before comparing. The original exact comparison is kept as a fast path, with the normalized comparison as a fallback.

This means the TOC works correctly whether the host serves .html URLs or pretty URLs.

Test

Added toc_js_normalizes_urls_for_pretty_urls test that verifies the generated toc.js contains the URL normalization logic.

Full test suite passes on macOS ARM (Apple Silicon): 119 tests, 0 failures.

When a hosting service (like Cloudflare Pages) strips .html from URLs,
the TOC sidebar highlighting breaks because the current page URL no
longer matches the link hrefs which contain .html.

This adds a normalizeUrl() function that strips .html suffixes before
comparing, so the TOC correctly highlights the active page regardless
of whether the host uses pretty URLs.

Fixes rust-lang#3034
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 19, 2026

☔ The latest upstream changes (possibly #3028) made this pull request unmergeable. Please resolve the merge conflicts.

@ehuss
Copy link
Copy Markdown
Contributor

ehuss commented May 19, 2026

Thanks for the PR! I've decided to go with a slightly simpler solution in #3028.

Let me know if there is something it doesn't cover.

@ehuss ehuss closed this May 19, 2026
@rustbot rustbot removed the S-waiting-on-review Status: waiting on a review label May 19, 2026
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.

3 participants