Skip to content

Conversation

@dheeraj12347
Copy link

Problem

Table of Contents (TOC) highlighting is not working correctly for some pages.

Root Cause

The URL comparison logic in toc_recursive_main.html and toc_recursive_dropdown.html was failing due to trailing slash differences between include.my_entry and entry.url.

Example:

  • include.my_entry: /docs/api/
  • entry.url: /docs/api

These look the same but don't match as strings.

Solution

Normalize both URLs before comparison by removing trailing slashes using Jekyll's remove filter.

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

@dheeraj12347
Copy link
Author

@GitToTheHub Thank you for the review! I've updated both files to use the cleaner single-line comparison as you suggested:

Changed from:
{% assign normalized_my_entry = include.my_entry | remove: '/' %}
{% assign normalized_entry_url = entry.url | remove: '/' %}
{% if normalized_my_entry == normalized_entry_url %}

To:
{% assign entry_active = include.my_entry | remove: '/' == entry.url | remove: '/' %}
{% if entry_active %}

This is much cleaner and more readable. Changes have been pushed. Thanks for the improvement suggestion!

@GitToTheHub
Copy link
Contributor

Very good :)

@GitToTheHub
Copy link
Contributor

@erisu Is this fine to merge?

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.

2 participants