plusjade / jekyll-bootstrap

The quickest way to start and publish your Jekyll powered blog. 100% compatible with GitHub pages.
jekyllbootstrap.com
MIT License
3.35k stars 1.71k forks source link

Alphabetize Categories and Tags #276

Open shellscape opened 9 years ago

shellscape commented 9 years ago

It'd be a great advantage to be able to alphabetize both the categories and tags list on each respective page. When dealing with a large number of categories/tags it makes it very hard for users to pinpoint a tag or subject without any kind of organization.

Skimmed this from a few examples on Stack Exchange, and it works very well:

{% capture tags %}{% for tag in site.tags %}{{ tag[0] }}|{% endfor %}{% endcapture %}
{% assign sortedtags = tags | split:'|' | sort %}
{% for tag in sortedtags %}
  <h2 id="{{ tag }}-ref">{{ tag }}</h2>
  <ul>
    {% assign pages_list = site.tags[tag] %}
    {% include JB/pages_list %}
  </ul>
{% endfor %}