Description

Displays the site navigation in a Table of Content format.

Syntax

{% include toc.html %}

Example

Code

{%- assign default_paths = site.header_pages | default: site.pages  -%}
{%- assign page_paths = site.data.navigation.toc | default: default_paths -%}

<div class="table-of-contents">
  <ul>
  {%- for path in page_paths -%}
    {%- assign my_page = site.pages | where: "path", path.name | first | default: path -%}
    {%- if my_page.url -%}
      <!-- <a class="page-link" href="{{ my_page.url | relative_url }}"><h3>{{ my_page.title }}</h3></a> -->
      {%- if my_page.title and site.header_pages != nil -%}
          <li class="page-link"> <a href="{{ my_page.url }}"><h3>{{ my_page.title | escape }}</h3></a></li>
        {%- else -%}
          {%- if my_page.title -%}
            <li class="page-link"><h3><a href="{{ my_page.url | relative_url }}">{{ my_page.title | escape }}</a></h3></li>
          {%- endif -%}
        {%- endif -%}
    {%- else -%}
      <h3>{{ my_page.title }}</h3>
    {%- endif -%}
    {% if my_page.subfolderitems %}
      <ul class="nav-container">
          {% for entry in my_page.subfolderitems %}
            <li class="nav-item">
              <a class="page-link" href="{{ entry.url | relative_url }}">{{ entry.title }}</a>
            </li>
          {% endfor %}
      </ul>
    {% endif %}
  {%- endfor -%}
  </ul>
</div>
}