Fix the numeric sort of trending tags size.

This commit is contained in:
Cotes Chung 2020-10-24 22:20:59 +08:00
parent bf8996fb8b
commit 38b87cfdd7

View file

@ -8,24 +8,33 @@
{% assign MAX = 10 %} {% assign MAX = 10 %}
{% capture tags_array %} {% assign size_list = "" | split: "" %}
{% for tag in site.tags %} {% assign tag_list = "" | split: "" %}
{{ tag[1] | size }}::{{ tag[0] | replace: ' ', '-' }}
{% endfor %}
{% endcapture %}
{% assign all_tags = tags_array | split: " " | sort | reverse %} {% for tag in site.tags %}
{% assign count = 0 %} {% assign size = tag | last | size %}
{% assign size_list = size_list | push: size %}
{% assign tag_str = tag | first | replace: " ", "-" | append: "::" | append: size %}
{% assign tag_list = tag_list | push: tag_str %}
{% endfor %}
{% assign size_list = size_list | sort | reverse %}
{% assign tag_list = tag_list | sort_natural %}
{% assign trending_tags = "" | split: "" %} {% assign trending_tags = "" | split: "" %}
{% for iter in all_tags %} {% for size in size_list limit: MAX %}
{% assign count = count | plus: 1 %} {% for tag_str in tag_list %}
{% assign tag = iter | split: "::" | last %} {% assign tag = tag_str | split: "::" %}
{% assign tag_name = tag | first %}
{% assign trending_tags = trending_tags | push: tag %} {% assign tag_size = tag | last | plus: 0 %}
{% if tag_size == size %}
{% if count >= MAX %} {% unless trending_tags contains tag_name %}
{% assign trending_tags = trending_tags | push: tag_name %}
{% break %} {% break %}
{% endunless %}
{% endif %} {% endif %}
{% endfor %}
{% endfor %} {% endfor %}