Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Getting a sorted list of tags in Jekyll with no plugins
{% capture tags %}{% for tag in site.tags %}{{ tag[0] }}|{% endfor %}{% endcapture %}
{% assign sortedtags = tags | split:'|' | sort %}
{% for tag in sortedtags %}
<a name="{{ tag }}"></a>
<h2>{{ tag }}</h2>
{% for post in site.tags[tag] %}
<li><a href="{{ post.url }}">{{ post.title }}</a></li>
{% endfor %}
{% endfor %}

This comment has been minimized.

Copy link
Owner Author

@brikis98 brikis98 commented Apr 16, 2015

This is a slightly modified version of Christian Specht's hack. My tags contained spaces, so splitting on space would break one tag into many and not work correctly. The code above generates the tags without any extra spaces and uses the pipe (|) character as a delimiter instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment