Jekyll:对集合中的项目进行排序,同时在集合上循环
我想循环查看我的Jekyll站点中的所有集合,并在其中对该集合中的所有页面进行排序和列出 ,我可以循环浏览所有集合和项目:Jekyll:对集合中的项目进行排序,同时在集合上循环,jekyll,Jekyll,我想循环查看我的Jekyll站点中的所有集合,并在其中对该集合中的所有页面进行排序和列出 ,我可以循环浏览所有集合和项目: {%用于site.collections%} 来自{{collection.label}的项 {%assign pages=站点[collection.label]} {%页中的项目为%} {%endfor%} {%endfor%} 对于特定集合,我还可以从frontmatter对更新字段进行排序: {% assign sorted = site.programmi
{%用于site.collections%}
来自{{collection.label}的项
{%assign pages=站点[collection.label]}
{%页中的项目为%}
{%endfor%}
{%endfor%}
对于特定集合,我还可以从frontmatter对更新字段进行排序:
{% 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]
,但得到了相同的错误。这个错误的原因不是collection.docs
和site[collection.label]
之间的差异。相反,在其中一个集合中,有一个项目的frontmatter不包含update
字段。因此,它无法按此字段排序,因为并非所有项目都有此字段。类似地,如果类型在所有情况下都不可比较,则会出现相同的错误。在这种情况下,它们都应该是日期;如果其中一个不是有效的日期格式,则失败
我仍然认为这是一个非常模糊的错误消息