Skip to content

Instantly share code, notes, and snippets.

@xupyprmv
Created January 20, 2016 11:51
Show Gist options
  • Save xupyprmv/6540ee0ad741d21b9573 to your computer and use it in GitHub Desktop.
Save xupyprmv/6540ee0ad741d21b9573 to your computer and use it in GitHub Desktop.
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:' ',' ' }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment