Skip to content

Comments

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

Open
cobyfrombrooklyn-bot wants to merge 1 commit intorust-lang:masterfrom
cobyfrombrooklyn-bot:fix-issue-3034
Open

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

Conversation

@cobyfrombrooklyn-bot
Copy link

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 rustbot added the S-waiting-on-review Status: waiting on a review label Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: waiting on a review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants