【发布时间】:2021-09-20 19:09:07
【问题描述】:
下面给出了显示我正在使用的 Jekyll 主题标签的代码。它目前按字母顺序显示标签。我应该更改什么以通过帖子计数进行排序?我看到了a similar question,但他们使用的代码与这个主题中的代码非常不同。
{% capture site_tags %}{% for tag in site.tags %}{{ tag | first | downcase }}{{ tag | first }}{% unless forloop.last %}{% endunless %}{% endfor %}{% endcapture %}
{% assign site_tags = site_tags | split: '' | sort %}
{% capture site_tags %}{% for tag in site_tags %}{{ tag | split: '' | last }}{% unless forloop.last %}{% endunless %}{% endfor %}{% endcapture %}
{% assign site_tags = site_tags | split: '' %}
{% assign post_count = site.posts | size %}
{% capture tag_counts %}{% for tag in site_tags %}{{site.tags[tag] | size | times: 10 | plus: post_count | minus: 1 | divided_by: post_count }}{% unless forloop.last %},{% endunless %}{% endfor %}{% endcapture %}
{% assign tag_counts = tag_counts | split: ',' %}
<ul class="tags quick-links">
{% for tag in site_tags %}
{% assign tag_data = site.data.tags[tag] %}
{% capture tag_classes %}tag tag-size-{{ tag_counts[forloop.index0] }} tag-{{ tag | slugify }}{% endcapture %}
{% capture tag_name %}{% if tag_data.title %}{{ tag_data.title }}{% else %}{{ tag }}{% endif %}{% endcapture %}
<li><a href="{{ include.baseurl }}#{{ tag | slugify }}" class="{{ tag_classes }}">{{ tag_name }}<span class="count">{{ site.tags[tag] | size }}</span></a></li>
{% endfor %}
</ul>
【问题讨论】:
-
你能分享正在生成的带有截图的html吗?
-
@Chandan 我添加了截图。
-
能不能也分享一下生成的html
-
@Chandan view-source:iamsreeman.github.io/blog
-
只是为了确认你想要标签为
Philosophy[2], Quantum mechanics[2],Textbook[2],Atheism[1],Ethics[1],....