Skip to content

Instantly share code, notes, and snippets.

Embed
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>
<ul>
{% for post in site.tags[tag] %}
<li><a href="{{ post.url }}">{{ post.title }}</a></li>
{% endfor %}
</ul>
{% endfor %}
@brikis98

This comment has been minimized.

Copy link
Owner Author

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
You can’t perform that action at this time.