Skip to content

Instantly share code, notes, and snippets.

@brikis98
Created April 16, 2015 19:34
Show Gist options
  • Save brikis98/e71d6c736158080968f5 to your computer and use it in GitHub Desktop.
Save brikis98/e71d6c736158080968f5 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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