有没有一种方法可以按两个字段对Jekyll中的列表进行排序? [英] Is there a way to sort lists in Jekyll by two fields?

查看:58
本文介绍了有没有一种方法可以按两个字段对Jekyll中的列表进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用Jekyll/Liquid按两个字段对列表进行排序?例如,首先按年份排序,然后按标题排序.我已经尝试过:

Is there a way to sort lists by two fields with Jekyll/Liquid? For example, sorting first by year and then title. I have tried:

{% assign list = site.data.papers.papers | sort: 'year' | sort: 'title' %}

但是它仅根据最后一个字段(在本例中为标题)进行排序.对此进行了一些讨论,但是似乎没有合并就被冻结了: https://github .com/jekyll/jekyll/issues/1802

but that left it sorted only based on the last field, in this case the title. There was some discussion on this, but it seems to have been frozen without being merged: https://github.com/jekyll/jekyll/issues/1802

谢谢!

推荐答案

group_by进行救援:

{% assign years = site.data.papers.papers | group_by: "year" %}
{% assign yearsSorted = years | sort: "name" %}
<ul>
{% for y in yearsSorted %}
  <li>{{ y.name }}
    <ul>
      {% assign yearTitlesSorted = y.items | sort: "title" %}
      {% for t in yearTitlesSorted %}
      <li>{{ t.title }}</li>
      {% endfor %}
    </ul>
  </li>
{% endfor %}
</ul>

这篇关于有没有一种方法可以按两个字段对Jekyll中的列表进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆