如何按Front Matter对Jekyll Post进行排序



如何在Jekyll液体中按order对帖子进行排序。

---
layout: post
title: my title
order: 1
---

来源https://jekyllrb.com/docs/posts/

排序
对数组进行排序。哈希1的可选参数。属性名称2。幂级数(第一个或最后一个(

示例:

{{ page.tags | sort }}
{{ site.posts | sort: "author" }}
{{ site.pages | sort: "title", "last" }}
<ul>
{% for post in site.posts %}
<li>
<a href="{{ post.url }}">{{ post.title }}</a>
</li>
{% endfor %}
</ul>

发件人https://jekyllrb.com/docs/liquid/filters/:

{{ site.posts | sort: "author" }}

我认为,这应该做到:

<!-- or + last, see above -->
{% assign sorted_posts = site.posts | sort "order" %}
<ul>
{% for post in sorted_posts %}
<li>
<a href="{{ post.url }}">{{ post.title }}</a>
</li>
{% endfor %}
</ul>

最新更新