// Include this file ONLY when current.path[2] is defined
- var base = '/docs/' + current.path[1] + '/' + current.path[2] + '/';
- var dir = current.path[4] ? current.path[3] + '/' : '';
- var cur = current.path[4] || current.path[3];
- cur = cur === 'index' ? '' : cur + '.html';
- cur = base + dir + cur; 

- var sections = function(dir, selector) {
-    var secondaryPath = public.docs[current.path[1]][current.path[2]]
-    var data = dir ? secondaryPath[dir] && secondaryPath[dir]._data : secondaryPath._data;
-    if (!data) return [];

-    var section = [];
-    var selector = selector || function() { return true; };
-    var prefix = base + (dir ? dir + '/' : '');
-    for (prop in data) {
-      var item = data[prop];
-      item.slug = prop;
-      if (prop[0] !== '_' && !item.hide && selector(item)) {
-        var file = prop === 'index' ? '' : prop + '.html';
-        var href = prefix + file;
-        item.class = cur === href ? 'is-selected' : '';
-        item.file = file;
-        item.href = href;
-        item.navTitle = item.navTitle || item.title;
-        item.tooltip = item.description || item.intro || '';
-        section.push(item);
-      }
-    }
-    return section;
-  }
  
- var tutorial = sections('tutorial');
- var cookbook = sections('cookbook');
- var basics = sections('guide', function(item) { return item.basics; });
- var guide  = sections('guide', function(item) { return !item.basics; });
- var qs = sections('', function(item) { return item.slug === 'quickstart'; })[0] || {};
- var reference  = sections('', function(item) { return item.reference; });
- var resources  = sections('', function(item) { return item.resources; });

nav.side-nav.l-pinned-left.l-layer-4.l-offset-nav
  // SEARCH BAR
  header.side-nav-search.st-input-wrapper
    form.st-input-inner
      label(for="search-io" class="is-hidden") Search Docs
      input(type="search" id="search-io" placeholder="SEARCH DOCS...")
    button(class="mobile-trigger button" aria-label="View Docs Menu" ng-click="appCtrl.toggleDocsMenu($event)" md-button) Docs <span class="icon icon-arrow-drop-down"></span>

  div(class="side-nav-secondary" ng-class="appCtrl.showDocsNav ? 'is-visible' : ''")
    .nav-blocks
      .nav-title Tutorial
      .nav-primary-link(class="#{qs.class}")
        a(href="#{qs.href}" title="#{qs.tooltip}") #{qs.navTitle}
      .nav-sub-title Case Study: Tour of Heroes
      .nav-ordered-lists
        ol
          each item in tutorial
            li(class="#{item.class}"): a(href="#{item.href}" title="#{item.tooltip}") #{item.navTitle}

    .nav-blocks
      .nav-title Basics
      .nav-ordered-lists
        ol
          each item in basics
            li(class="#{item.class}"): a(href="#{item.href}" title="#{item.tooltip}") #{item.navTitle}    

    .nav-blocks
      .nav-title Developer Guide
      .nav-unordered-lists
        ul
          each item in guide
            li(class="#{item.class}"): a(href="#{item.href}" title="#{item.tooltip}") #{item.navTitle}

    .nav-blocks
      .nav-title Cookbook
      .nav-unordered-lists
        ul
          each item in cookbook
            li(class="#{item.class}"): a(href="#{item.href}" title="#{item.tooltip}") #{item.navTitle}

    .nav-blocks
      .nav-title Reference
      .nav-unordered-lists
        ul
          each item in reference
            li(class="#{item.class}"): a(href="#{item.href}" title="#{item.tooltip}") #{item.navTitle}
    
    .nav-blocks
      .nav-title Resources
      .nav-unordered-lists
        ul
          each item in resources
            li(class="#{item.class}"): a(href="#{item.href}" title="#{item.tooltip}") #{item.navTitle}


script.
  // Could put in appCtrl but only needed here and clear here
  (function scrollToSelectedLink() {
    var sideNav = document.getElementsByClassName('side-nav')[0];    
    var link = sideNav.getElementsByClassName('is-selected')[0];
    if(link && link.offsetTop > window.innerHeight){
      sideNav.scrollTop = link.offsetTop - (window.innerHeight/2);
      //alert("offsetTop: " + link.offsetTop + " side-nav top is " + sideNav.scrollTop);          
    }    
  })()
