{#
   The left sidebar for singleton pages provides navigation is for topics that
   have no child pages. This sidebar contains only links to all the level zero
   and level one headers for all content in the site. It should only be used for
   document section that have only a section definition file, `_index.md`.
#}

<div class="left-sidebar" aria-label="Site navigation">
  <nav class="scrollable-sidebar">
    {% set index = get_section(path="_index.md") %}
    <h3>{{ index.title }}</h3>
    <ul class="notes">
      {% for s in index.subsections %}
        {% set subsection = get_section(path=s) %}
        {% set active = "" %}
        {% if current_url == subsection.permalink %}
          {% set active = " active" %}
        {% endif %}
  
        <li>      
          <a class="note-link {{ active }}" href="{{ subsection.permalink | safe }}">
            {{ subsection.title }}
          </a>  
          {% 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>
</div>