如何解决Github页面中的液体过滤器
我正在使用github页面构建一个网页。在我的_posts
目录下,我保留了许多博客文章。帖子的yaml前题有一个变量display_post
。我想显示标签technical-writing
按时间排序的帖子列表。我为此使用了液体过滤器(https://jekyllrb.com/docs/liquid/filters/)。以下代码产生所需的输出。
{% assign postsByYear = site.tags.technical-writing | group_by_exp:"post","post.date | date: '%Y'" %}
{% for year in postsByYear %}
<h2>{{ year.name }}</h2>
{% assign postsByMonth = year.items | group_by_exp:"post","post.date | date: '%B'" %}
{% for month in postsByMonth %}
<h3>{{ month.name }}</h3>
{% assign postsByDate = month.items | sort:"date" | reverse %}
<ul>
{% for post in postsByDate %}
<li>
{{ post.date | date: "%B %-d,%Y" }} | <a href="{{ post.url | relative_url }}">{{ post.title }}</a>
</li>
{% endfor %}
</ul>
{% endfor %}
{% endfor %}
我想生成一个帖子列表,其中display_post
的值为display
。另外,在那之后,我想按年份,月份等对帖子进行排序。为了仅提取那些具有期望值display_post
的帖子,我用以下代码替换了上面代码的前两行。这将不返回任何输出。
{% assign postsByYearD = site.tags.technical-writing | where: "display_post","display" %}
{% for year in postsByYearD %}
但是,如果我使用第一个代码,但将<ul>
标记括在if语句中,如下所示,则仅显示display_post
具有值显示的那些帖子,但是它们的年份和月份已打印。
{% if post.display_post == display %}
{% endif %}
此外,即使我能够填充postsByYearD
,我也不知道如何从中创建postsByYear
变量。
因此,我的问题是,我如何只收集display_post
是display
的帖子,并按时间对其进行排序?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。