Skip to content

Commit 4bf85f7

Browse files
committed
fix: normalize URL comparison in TOC highlighting to handle trailing slashes
1 parent 5a25e6b commit 4bf85f7

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

www/_includes/toc_recursive_dropdown.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
{% for entry in include.entries %}
2+
{% assign normalized_my_entry = include.my_entry | remove: '/' %}
3+
{% assign normalized_entry_url = entry.url | remove: '/' %}
4+
25
{% if entry.url != null %}
36
<li>
4-
<a class="{% if include.my_entry == entry.url %}this-page{% endif %}" href="{{ include.path_to_root }}{{ entry.url }}">
7+
<a class="{% if normalized_my_entry == normalized_entry_url %}this-page{% endif %}" href="{{ include.path_to_root }}{{ entry.url }}">
58
{{ entry.name }}
69
</a>
710
</li>

www/_includes/toc_recursive_main.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
<ul class="site-toc">
22
{% for entry in include.entries %}
33

4+
{% assign normalized_my_entry = include.my_entry | remove: '/' %}
5+
{% assign normalized_entry_url = entry.url | remove: '/' %}
6+
47
<li>
58
{% if entry.children %}
69
<span class="toc-section-heading">
710
{{ entry.name }}
811
</span>
912
{% else %}
10-
<a class="{% if include.my_entry == entry.url %}this-page{% endif %}" href="{{ include.path_to_root }}{{ entry.url }}">
13+
<a class="{% if normalized_my_entry == normalized_entry_url %}this-page{% endif %}" href="{{ include.path_to_root }}{{ entry.url }}">
1114
{{ entry.name }}
1215
</a>
13-
{% if include.my_entry == entry.url %}
16+
{% if normalized_my_entry == normalized_entry_url %}
1417
<span class="entry-highlight"></span>
1518
{% endif %}
1619
{% endif %}
1720

21+
1822
{% comment %}
1923
Insert page-specific ToC here if this is the entry for this page
2024
{% endcomment %}
21-
{% if include.my_entry == entry.url %}<div id="page-toc" class="page-toc"></div>{% endif %}
25+
{% if normalized_my_entry == normalized_entry_url %}<div id="page-toc" class="page-toc"></div>{% endif %}
26+
2227

2328
{% if entry.children %}
2429
{% include toc_recursive_main.html entries=entry.children my_entry=include.my_entry path_to_root=include.path_to_root %}

0 commit comments

Comments
 (0)