Skip to content

Instantly share code, notes, and snippets.

@danieltomasz
Created September 14, 2017 16:50
Show Gist options
  • Save danieltomasz/da9708b3bbe2b4a26bc54034a750e3af to your computer and use it in GitHub Desktop.
Save danieltomasz/da9708b3bbe2b4a26bc54034a750e3af 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