A liquid include file for Jekyll that allows an object to be grouped by an array. For instance, it could be used to list posts by tag.
Copy the group-by-array.html
file into your Jekyll project's _includes
directory.
Include the file in your template, passing in a collection
and a field
variable. Then Jekyll Group-By-Array will set group-names
and group-items
global variables with the results.
For example:
---
layout: page
title: Tags
permalink: /tags/
---
{% include group-by-array.html collection=site.posts field='tags' %}
<ul>
{% for tag in group_names %}
{% assign posts = group_items[forloop.index0] %}
<li>
<h2>{{ tag }}</h2>
<ul>
{% for post in posts %}
<li>
<a href='{{ site.baseurl }}{{ post.url }}'>{{ post.title }}</a>
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
For an extended example, checkout out this group-by-array example branch of the Fresh Jekyll repository.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request