summaryrefslogtreecommitdiffstats
path: root/docs/theme/Toc.jinja
blob: 2670b622fe9b9c919ab0b9d98421f0f58538a2cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
{# def toc, page #}

{% macro render_page(url, title) %}
{% if url != "/" -%}
<div class="page {{ 'active' if page.url == url else '' }}">
  <a href="{{ url }}#">{{ title }}</a>
</div>
{%- endif %}
{% endmacro %}


{% macro render_collapsable(title, children) %}
<details open>
  {% if title %}<summary>{{ title }}</summary>{% endif %}
  {{ render_children(children) }}
</details>
{% endmacro %}


{% macro render_section(title, children) %}
<section open>
  {% if title %}<h2>{{ title }}</h2>{% endif %}
  {{ render_children(children) }}
</section>
{% endmacro %}


{% macro render_children(children, collapsable=True) %}
  {%- for url, title, sub_children in children %}
    {% if sub_children -%}
      {% if collapsable -%}
        {{ render_collapsable(title, sub_children) }}
      {%- else -%}
        {{ render_section(title, sub_children) }}
      {%- endif %}
    {%- else -%}
      {{ render_page(url, title) }}
    {%- endif %}
  {%- endfor %}
{% endmacro %}


<div {{ attrs.render(class="cd-toc", data_component="Toc") }}>
  {{ render_children(toc, collapsable=False) }}
</div>