spencermathews
3/7/2014 - 5:49 PM

Nested Jekyll page navigation without plugins

Nested Jekyll page navigation without plugins

{% capture html %}
<ul>
    {% if include.context == "/" %}
        <li class="{% if page.url == "/" %}active{% endif %}">
            <a href="{{ site.baseurl }}/">{{ site.title }}</a>
        </li>
    {% endif %}

    {% assign entries = site.pages | sort: "path" %}
    {% for entry in entries %}

        {% capture slug    %}{{ entry.url | split: "/"   | last                       }}{% endcapture %}
        {% capture current %}{{ entry.url | remove: slug | remove: "//" | append: "/" }}{% endcapture %}

        {% if current == include.context %}
            <li class="{% if page.url contains entry.url %}active{% endif %}">
                <a href="{{ site.baseurl }}{{ entry.url }}">{{ entry.title }}</a>
                {% include navigation.html context=entry.url %}
            </li>
        {% endif %}

    {% endfor %}
</ul>
{% endcapture %}{{ html | strip_newlines | replace:'    ','' | replace:'    ','' | replace:'  ',' ' }}