fix: normalize URL comparison in TOC highlighting #1463
+10
−4
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
Table of Contents (TOC) highlighting is not working correctly for some pages.
Root Cause
The URL comparison logic in
toc_recursive_main.htmlandtoc_recursive_dropdown.htmlwas failing due to trailing slash differences betweeninclude.my_entryandentry.url.Example:
/docs/api//docs/apiThese look the same but don't match as strings.
Solution
Normalize both URLs before comparison by removing trailing slashes using Jekyll's
removefilter.Added:
{% assign normalized_my_entry = include.my_entry | remove: '/' %} {% assign normalized_entry_url = entry.url | remove: '/' %} ## Solution Normalize both URLs before comparison by removing trailing slashes using Jekyll's `remove` filter. Added: ```liquid {% assign normalized_my_entry = include.my_entry | remove: '/' %} {% assign normalized_entry_url = entry.url | remove: '/' %} Then compare: text {% if normalized_my_entry == normalized_entry_url %} Files Changed www/_includes/toc_recursive_main.html www/_includes/toc_recursive_dropdown.html Why This Works Removes all / characters from both URLs before comparison Makes the comparison consistent regardless of trailing slashes Current page highlighting now works correctly No JavaScript changes needed