Last active
January 21, 2024 11:10
Example Jekyll group_by filter #jekyllrb
This file contains hidden or 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
{% comment %} | |
items is a collection, though I think it coule be any content type | |
{% endcomment %} | |
{% comment %} Create the group. {% endcomment %} | |
{% assign items_grouped = site.items | group_by: 'category' | sort: 'name' | reverse %} | |
{% comment %} | |
The above returns, for example, which is why we sort by 'name' | |
{"name"=>"category1_value", "items"=>[#, #, #, #, #]}{"name"=>"category2_value", "items"=>[#, #, #, #]} | |
{% endcomment %} | |
{% comment %} Loop through the groups {% endcomment %} | |
{% for group in items_grouped %} | |
{% comment %} Create the items within the groups, now sorting by the criteria you want them sorted {% endcomment %} | |
{% assign items = item.items | sort: 'date' | reverse %} | |
{% comment %} Loop through the items {% endcomment %} | |
{% for item in items %} | |
{{ item.title }} | |
{% endfor %} | |
{% endfor %} |
It's better to do itemObj.name | remove: '[' | remove: ']' | remove: '"' | trim
otherwise it fails with posts with no (blank) categories
But even with Jekyll 4.3.3 (as of 2024-06-21) it's still an issue :(
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is this
group_by: array
problem solved?It still occurred when
{{ site.posts | group_by: categories }}
. Notcategory
.Anyone know this? please help