{#def page_toc, max_depth=3 #}

{% macro render_sub_items(pages) %}
{%- for section in pages %}
  <li class="indent-{{ section.level }}">
    <a href="#{{ section.id }}"><span>{{ section.name }}</span></a>
  </li>
  {% if section.level <= max_depth -%}
    {{ render_sub_items(section.children) }}
  {%- endif %}
{%- endfor %}
{% endmacro %}

<ul {{ attrs.render(class="cd-toc-page", data_component="TocPage") }}>
{%- for section in page_toc %}
  <li class="indent-{{ section.level }}">
    <a href="#{{ section.id }}"><span>{{ section.name }}</span></a>
  </li>
  {{ render_sub_items(section.children) }}
{%- endfor %}
</ul>
