问题描述
我正在使用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 (将#修改为@)