我已经有一个工作代码,可以显示收集帖子中的所有标签,并计算它们在所有帖子中的数量。
这里:
{% assign tags = site.blog | map: 'tags' | uniq %}
{% assign postInTagCount = 0 %}
<div class="blog-tags__tags-wrapper">
{% for tag in tags %}
<a href="/blog/tags/#{'#'}{{ tag | downcase }}">
<div class="tags_wrapper__tag">
{{ tag }}
{% for post in site.blog %}
{% if post.tags contains tag %}
{% capture postInTagCount %}{{ postInTagCount | plus:1 }}{% endcapture %}
{% endif %}
{% endfor %}
{% if postInTagCount <> 0 %} [{{ postInTagCount }}]{% endif %}
{% capture postInTagCount %}0{% endcapture %}
</div>
</a>
{% endfor %}
但我想要显示5个最受欢迎的标签,是在选定的集合的帖子中找到的。
我有一个例子:https://www.codeofclimber.ru/tags/
但我不确定这个网站是否使用了Jekyll。在作者存储库的Gitkhab上,我没有找到他的网站。
我请求你的帮助。谢谢。
发布于 2017-10-29 17:49:04
该网站的作者确实使用了Jekyll。:)
查看他的article,看看他是如何使用定制的液体过滤器做到这一点的,或者直接在SO @hal上联系他。
发布于 2017-10-30 07:08:27
也许可以通过捕获循环并在其中写入内容:首先是var PostInTagCount,这是您选择的分隔符,不能出现在标记名称中,然后是标记,然后是辅助分隔符。
完成后,您可以使用辅助分隔符拆分捕获的内容,并创建一个新的按A..B排序的循环。因为第一个字符是您的var PostInTagCount,所以它应该可以完成这项工作。
https://stackoverflow.com/questions/47003172
复制相似问题