【发布时间】:2015-03-24 12:21:56
【问题描述】:
我在 jekyll 中学习流媒体,但我很难按月统计帖子数量。计算每个标签或类别的帖子数量似乎很容易(因为有变量 site.tags 和 site.categories),我对此没有任何问题。这里是my live example,用于计算每个标签/类别的帖子的源代码可在github 上找到。为了按月计算帖子,我尝试使用像
这样的计数器{% capture counter %}{{ counter | plus:1 }} {% endcapture %} {% endif %}
但它的各种用途并没有给我预期的计数,我现在怀疑有更好的方法。问题是我如何修改下面的代码,使其显示月份(给定年份)而不是每个类别的帖子数?
{% capture site_cats %}{% for cat in site.categories %}{{ cat | first }}
{%unless forloop.last %},{% endunless %}{% endfor %}{% endcapture %}
{% assign sortedcats = site_cats | split:',' | sort %}
{% for category in sortedcats %}
{{category }}{{site.categories[category] | size }}
<ul>
{% for post in site.categories[category] %}
{% if post.url %}
<li><a href="{{ post.url }}">{{ post.title }}</a>
<time> — {{ post.date | date: "%a %e-%b-%Y" }}</time>
</li>
{% endif %}
{% endfor %}
</ul>
{% endfor %}
【问题讨论】:
-
我尽量避免使用 github 端不支持的插件。