我想循环遍历我的Jekyll站点中的所有集合,并在其中对集合中的所有页面进行排序和列出。
Based on this stackoverflow answer,我可以循环遍历所有集合和项:
{% 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 %}对于特定的集合,我还可以从前端对更新字段进行排序:
{% assign sorted = site.programming | sort: 'update' %}但是,如果我尝试将其应用于第一个示例,它就失败了:
{% assign pages = site[collection.label] | sort: 'update' %}这就产生了一个相当普遍无用的错误:
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.我猜想site[collection.label]会以某种方式返回与site.programming不同的内容,但我不知道什么,也不知道如何解决这个问题。
编辑:我尝试使用collection.docs而不是site[collection.label],并得到了同样的错误。
发布于 2020-11-23 19:39:52
导致此错误的原因并不是collection.docs和site[collection.label]之间的差异。相反,在其中一个集合中,有一个项目未包含update字段。因此,它无法按此字段进行排序,因为并非所有项目都有。同样,如果类型并非在所有情况下都是可比的,则会得到相同的错误。在这种情况下,它们都应该是日期;如果其中一个不是有效的日期格式,则失败。
我仍然认为这是一个非常模糊的错误信息。
https://stackoverflow.com/questions/64934580
复制相似问题