Jekyll - 无法按日期反向排序

问题描述 投票:0回答:2

我正在尝试对我的博客上的 3 个最新的 '精选' 帖子进行排序,但我当前的 for 循环不允许我对集合进行排序以首先显示最新的帖子。

我下面的内容输出了我博客上的三篇最新帖子,但忽略了 where_exp 并显示了特色帖子和非特色帖子。 如果我在按日期排序后删除 'reverse' 过滤器,它将仅对精选帖子进行排序,但对它们进行从旧到最新的排序。我尝试在 for 循环之前重新分配 featured-posts 变量以再次按反向日期排序,但它不起作用。

到目前为止我尝试过的所有方法都不允许我在我的网站上显示三个最新的特色帖子,我希望有人能告诉我哪里出错了..

发表前言:

---
post_date: 2017-08-14 00:00:00
featured: true
---

页面For循环:

{% assign sorted-posts = site.posts | sort: 'post_date' | reverse %}
{% assign featured-posts = sorted-posts | where_exp:"post","post.featured" %}
{% for post in featured-posts limit:3 %}
  <h2><a href="{{ post.url }}">{{ post.title | truncate: 58 }}</a></h2>
{% endfor %}

输出:

Three most recent posts on the website regardless of whether they're 'featured' or not.

提前致谢

jekyll liquid
2个回答
4
投票

通过升级 Jekyll 解决。我运行的是 3.0.0 版本,升级到 3.5.2 后问题已解决。


0
投票

我遇到了同样的问题,这让我很困惑。最后我发现这是因为网络缓存。那么使用

Ctrl + F5
强制刷新页面就可以了。

© www.soinside.com 2019 - 2024. All rights reserved.