<nav id="sidebar">
  <div id="header-wrapper">
    <div id="header">
      {{ partial "logo.html" . }}
    </div>
    {{ if .Site.Params.search }}
        {{ partial "search.html" . }}
    {{ end }}
</div>


  <div class="highlightable">
    <ul class="topics">
      {{ $page := . }}
      {{ if .Site.Params.menu }}
        {{ $.Scratch.Set "menuItems" (slice) }}
        {{ range $i, $key := .Site.Params.menu }}
          {{ if isset $page.Site.Sections $key }}
            {{ $.Scratch.Add "menuItems" $key }}
          {{ else }}
            <li class="dd-item"><div class="notices warning"><p>
            {{ printf "Unknown section '%s' found in site menu" $key }}
            </p></div></li>
          {{ end }}
        {{ end }}
      {{ else }}
        {{ $.Scratch.Set "menuItems" .Site.Sections }}
      {{ end }}
      {{ $menuItems := $.Scratch.Get "menuItems" }}
      {{ range $i, $key := $menuItems }}
      {{ if ne $key "" }}

      {{ if not $.Site.Params.menu }}
        {{ $.Scratch.Set "currentItem" (index $page.Site.Sections $i) }}
      {{ else }}
        {{ $.Scratch.Set "currentItem" (index $page.Site.Sections $key) }}
      {{ end }}
      {{ $value := $.Scratch.Get "currentItem" }}
      {{ $first := (index $value 0).Page }}

      <li class="dd-item {{ if eq $page.RelPermalink $first.RelPermalink }}active{{ end }} {{if in $page.RelPermalink $first.RelPermalink }}parent{{ end }}" data-nav-id="{{ $first.RelPermalink }}">
        <a href="{{ $first.RelPermalink }}">
          <span>
            {{ if isset $first.Params "icon" }}
              {{ printf $first.Params.icon | safeHTML }}
            {{ end }}
             {{ $first.Title }}
            {{ if $page.Site.Params.showVisitedLinks}}
              <i class="fa fa-check read-icon"></i>
             {{ end }}
           </span>
        </a>
        {{ if gt $value.Len 1}}
        <ul>
          {{ range $k, $p := $value }}
          {{ if gt $k 0 }}
            <li class="dd-item {{ if eq $page.RelPermalink $p.Page.RelPermalink }}active{{ end }}" data-nav-id="{{ $p.Page.RelPermalink }}">
              <a href="{{ $p.Page.RelPermalink }}">
                <span>{{ $p.Page.Title }}    {{ if $page.Site.Params.showVisitedLinks}}  <i class="fa fa-check read-icon">  {{ end }} </i></span>
              </a>
            </li>
          {{ end }}
          {{ end }}
        </ul>
        {{ end }}
      </li>
      {{ end }}
      {{ end }}
    </ul>
    <hr>
     {{ if .Site.Params.showVisitedLinks}}
     <a class="padding" href="#" data-clear-history-toggle=""><i class="fa fa-fw fa-history"></i> Clear History</a>
     {{ end }}
    <section id="footer">
      <p>Built with <a href="https://github.com/matcornic/hugo-theme-learn"><i class="fa fa-heart"></i></a> from <a href="http://getgrav.org">Grav</a> and <a href="http://gohugo.io/">Hugo</a></p>
    </section>
  </div>
</nav>