gpt4 book ai didi

Jekyll 按类别显示收藏

转载 作者:行者123 更新时间:2023-12-03 23:24:26 26 4
gpt4 key购买 nike

我无法弄清楚如何按类别对集合的内容进行排序。我发现了一个关于如何按类别对帖子进行排序的非常相似的问题,但它似乎不适用于集合 Jekyll display posts by category .

假设我有一个名为“汽车”的集合,有两个类别:“旧”和"new"。如何仅显示类别为“旧”的汽车?

最佳答案

您可以像页面或帖子等任何其他对象一样对集合进行排序、分组或过滤。

_my_collection/mustang.md

---
category: 'old'
abbrev: tang
---
mustang content

_my_collection/corvette.md
---
category: 'new'
abbrev: vet
---
corvette content

过滤
{% assign newcars = site.my_collection | where: "category", "new" %}

排序
{% assign allcarssorted = site.my_collection | sort: "category" %}

分组
{% assign groups = site.my_collection | group_by: "category" | sort: "name" %}

这对您的汽车进行分组,然后按类别名称对组进行排序。
{% for group in groups %}
{{ group.name }}
{% for item in group.items %}
{{item.abbrev}}
{%endfor%}
{%endfor%}

关于Jekyll 按类别显示收藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28100220/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com