{#
   The left sidebar for large document sections navigation for topics that
   have child pages. This sidebar contains links to all the pages, and all their
   level-one headers, for all the content in the section.
#}

<nav class="left-sidebar" aria-label="Site navigation">
  {% set index = get_section(path="_index.md") %}
  <h3>{{ index.title }}</h3>
  <ul class="notes">
    {% for subsection in index.subsections %}
      {% set active = "" %}
      {% if current_url == subsection.permalink %}
        {% set active = " active" %}
      {% endif %}

      <li>      
        <h3><a class="note-link {{ active }}" href="{{ subsection.permalink | safe }}">
          {{ subsection.title }}
        </h3>
  
        {% set pagecount = subsection.pages | length %}
        {% if pagecount > 0 %}
          <ul>
            {% for page in subsection.pages %}
              <li><a class="note-link" href="{{ page.permalink | safe }}">{{ page.title }}</a></li>
            {% endfor %}
          </ul>
        {% else %}
          <ul>
            {% for dest in subsection.toc %}
              <li><a class="note-link" href="{{ dest.permalink | safe }}">{{ dest.title }}</a></li>
            {% endfor %}
          <ul>
        {% endif %}
      </li>
    {% endfor %}
  <ul>
</nav>
