Skip to content

Commit 6f25216

Browse files
hsyl20claude
andcommitted
Docs: make sidebar section titles clickable
Override the TeXt theme's _includes/sidebar/toc.html, which rendered each top-level nav item as plain text. Turn the title into a link when the nav item has a url, with active-state handling. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 5f8af2f commit 6f25216

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

_includes/sidebar/toc.html

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{%- comment -%}
2+
Local override of the TeXt theme's sidebar TOC.
3+
4+
Upstream renders each top-level item as plain, unclickable text:
5+
<li class="toc-h1">{{ _item.title }}</li>
6+
Our navigation gives every section (Home, Explanation, ...) a `url`, so we
7+
turn the title into a link when a `url` is present, and mark it active when
8+
it is the current page. Items without a `url` keep the plain header style.
9+
{%- endcomment -%}
10+
{%- if page.sidebar.nav -%}
11+
<div class="sidebar-toc">
12+
{%- assign _sidebar_nav = site.data.navigation[page.sidebar.nav] -%}
13+
{%- if _sidebar_nav -%}
14+
<ul class="toc toc--navigator">
15+
{%- for _item in _sidebar_nav -%}
16+
{%- if _item.url -%}
17+
{%- include snippets/get-nav-url.html path=_item.url -%}
18+
{%- assign _nav_url = __return -%}
19+
{%- include snippets/get-nav-url.html path=page.url -%}
20+
{%- assign _page_url = __return -%}
21+
{%- if _nav_url == _page_url -%}
22+
<li class="toc-h1 active"><a href="{{ _nav_url }}">{{ _item.title }}</a></li>
23+
{%- else -%}
24+
<li class="toc-h1"><a href="{{ _nav_url }}">{{ _item.title }}</a></li>
25+
{%- endif -%}
26+
{%- else -%}
27+
<li class="toc-h1">{{ _item.title }}</li>
28+
{%- endif -%}
29+
{%- if _item.children -%}
30+
{%- for _child in _item.children -%}
31+
{%- include snippets/get-nav-url.html path=_child.url -%}
32+
{%- assign _nav_url = __return -%}
33+
{%- include snippets/get-nav-url.html path=page.url -%}
34+
{%- assign _page_url = __return -%}
35+
{%- if _nav_url == _page_url -%}
36+
<li class="toc-h2 active"><a href="{{ _nav_url }}">{{ _child.title }}</a></li>
37+
{%- else -%}
38+
<li class="toc-h2"><a href="{{ _nav_url }}">{{ _child.title }}</a></li>
39+
{%- endif -%}
40+
{%- endfor -%}
41+
{%- endif -%}
42+
{%- endfor -%}
43+
</ul>
44+
{%- endif -%}
45+
</div>
46+
{%- endif -%}

0 commit comments

Comments
 (0)