Fix #3034: TOC highlighting on hosts with pretty URLs#3038
Open
cobyfrombrooklyn-bot wants to merge 1 commit intorust-lang:masterfrom
Open
Fix #3034: TOC highlighting on hosts with pretty URLs#3038cobyfrombrooklyn-bot wants to merge 1 commit intorust-lang:masterfrom
cobyfrombrooklyn-bot wants to merge 1 commit intorust-lang:masterfrom
Conversation
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
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
When a hosting service (like Cloudflare Pages) strips
.htmlfrom 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 comparisonlink.href === current_pagenever matches.Fix
Added a
normalizeUrl()function in the TOC initialization JS that strips.htmlsuffixes (and normalizes/index.htmlto/) 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
.htmlURLs or pretty URLs.Test
Added
toc_js_normalizes_urls_for_pretty_urlstest that verifies the generatedtoc.jscontains the URL normalization logic.Full test suite passes on macOS ARM (Apple Silicon): 119 tests, 0 failures.