Created
April 16, 2015 19:34
-
-
Save brikis98/e71d6c736158080968f5 to your computer and use it in GitHub Desktop.
Getting a sorted list of tags in Jekyll with no plugins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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 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.