I want to loop over all of the collections in my Jekyll site, and within that I want to sort and list all of the pages in that collection.
Based on this stackoverflow answer, I can loop through all the collections and items:
{% for collection in site.collections %}
<h2>Items from {{ collection.label }}</h2>
<ul>
{% assign pages = site[collection.label] %}
{% for item in pages %}
<li><a href="{{ item.url }}">{{ item.title }}</a></li>
{% endfor %}
</ul>
{% endfor %}
For a specific collection, I can also sort the update field from the frontmatter:
{% assign sorted = site.programming | sort: 'update' %}
But if I try to apply this to the 1st example, it fails:
{% assign pages = site[collection.label] | sort: 'update' %}
This gives a rather generically useless error:
Liquid Exception: Liquid error (line 30): comparison of Array with Array failed in index.md
Error: Liquid error (line 30): comparison of Array with Array failed
Error: Run jekyll build --trace for more information.
I'm guessing that somehow site[collection.label]
returns something different than site.programming
, but I'm not sure what, or how to solve this.
EDIT: I tried using collection.docs
instead of site[collection.label]
and got the same error.
The cause of this error turned out not to be the difference between collection.docs
and site[collection.label]
. Rather, in one of the collections, there was an item where the frontmatter did not contain the update
field. As a result, it couldn't sort by this field because not all items had it. Similarly, you get the same error if the types are not comparable in all cases. In this case, they were all supposed to be dates; if one was not a valid date format, it failed.
I still think this is a terribly ambiguous error message.