【问题标题】:Jekyll display collection by categoryJekyll 按类别展示合集
【发布时间】:2015-01-22 23:00:34
【问题描述】:

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

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

【问题讨论】:

    标签: jekyll


    【解决方案1】:

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

    _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%}
    

    【讨论】:

    • 你能问一个真正的问题,解释你想要做什么吗?
    • 教程集合,像树一样组织(主题、子主题、子子主题等)。我创建了文件夹来反映这一点,但我想知道如何在菜单或子主题列表中访问结构......
    • 不是评论中的问题。关于 SO 的真正问题。
    • 哦,对了,我还在探索 Jelyll。稍后可能会发布。
    猜你喜欢
    • 2014-01-19
    • 1970-01-01
    • 2018-07-31
    • 1970-01-01
    • 1970-01-01
    • 2019-03-26
    • 1970-01-01
    • 2018-04-18
    • 2018-07-09
    相关资源
    最近更新 更多