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 %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
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.