Improve nav_list helper to be used with any type of navigation list defined in navigation.yml data file

- Close #272
This commit is contained in:
Michael Rose 2016-04-18 16:22:53 -04:00
parent 8cba6c6c41
commit 3e0527fa78
2 changed files with 30 additions and 7 deletions

View file

@ -1,21 +1,42 @@
{% include base_path %} {% include base_path %}
{% assign navigation = site.data.navigation[page.sidebar.nav] %} {% assign navigation = site.data.navigation[include.nav] %}
<nav class="nav__list"> <nav class="nav__list">
{% if page.sidebar.title %}<header><h4 class="nav__title" style="padding: 0;">{{ page.sidebar.title }}</h4></header>{% endif %} {% if page.sidebar.title %}<header><h4 class="nav__title" style="padding: 0;">{{ page.sidebar.title }}</h4></header>{% endif %}
<ul> <ul>
{% for nav in navigation %} {% for nav in navigation %}
<li><span class="nav__sub-title">{{ nav.title }}</span> <li>
{% if nav.url %}
{% comment %}internal/external URL check{% endcomment %}
{% if nav.url contains "http" %}
{% assign domain = "" %}
{% else %}
{% assign domain = base_path %}
{% endif %}
<a href="{{ domain }}{{ nav.url }}"><span class="nav__sub-title">{{ nav.title }}</span></a>
{% else %}
<span class="nav__sub-title">{{ nav.title }}</span>
{% endif %}
{% if nav.children != null %} {% if nav.children != null %}
<ul> <ul>
{% for child in nav.children %} {% for child in nav.children %}
{% assign nav_url = child.path | prepend: "/" | prepend: page.sidebar.nav | prepend: "/" | append: "/" %} {% comment %}internal/external URL check{% endcomment %}
{% if nav_url == page.url %} {% if child.url contains "http" %}
{% assign domain = "" %}
{% else %}
{% assign domain = base_path %}
{% endif %}
{% comment %}set "active" class on current page{% endcomment %}
{% if child.url == page.url %}
{% assign active = "active" %} {% assign active = "active" %}
{% else %} {% else %}
{% assign active = "" %} {% assign active = "" %}
{% endif %} {% endif %}
<li><a href="{{ nav_url | prepend: base_path }}" class="{{ active }}">{{ child.title }}</a></li>
<li><a href="{{ domain }}{{ child.url }}" class="{{ active }}">{{ child.title }}</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
{% endif %} {% endif %}
@ -23,3 +44,5 @@
{% endfor %} {% endfor %}
</ul> </ul>
</nav> </nav>

View file

@ -18,7 +18,7 @@
{% if s.text %}{{ s.text | markdownify }}{% endif %} {% if s.text %}{{ s.text | markdownify }}{% endif %}
{% endfor %} {% endfor %}
{% if page.sidebar.nav %} {% if page.sidebar.nav %}
{% include nav_list items=page.sidebar.nav %} {% include nav_list nav=page.sidebar.nav %}
{% endif %} {% endif %}
{% endif %} {% endif %}
</div> </div>