You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
blog/_includes/tag_list.html

88 lines
3.0 KiB

{% comment %}Sort decreasingly, alphabetically by tag frequency and by name.
After building a data structure like this:
frequency|tag name
==================
000008|mytag
010000|anothertag
000010|three
000010|four
000010|six
000010|five
it becomes:
frequency|tag_name
==================
010000|anothertag
000010|six
000010|three
000010|four
000010|five
000008|mytag
where the number of leading zeros for each frequency is computed with:
base_ten_power = len(str(max(number_of_posts_per_tag))) + 1
leading_zeros = base_ten_power - len(str(frequency))
{% endcomment %}
{% comment %}Get the frequency of the tag with the maximum frequency.
{% endcomment %}
{% assign x = '' %}
{% for t in site.tags %}
{% assign x = x | append: t[1].size | append: ',' %}
{% endfor %}
{% assign b = x | split: ',' | sort | last | size %}
{% comment %}Str to int and add a leading zero later.
{% endcomment %}
{% assign base_ten_power = b | plus: 0 | plus: 1 %}
{% assign tags = '' %}
{% assign leading_zeros = '' %}
{% for t in site.tags %}
{% capture tag_frequency %}{{ t[1].size }}{% endcapture %}
{% assign len_tag_frequency = tag_frequency | size %}
{% comment %}Prepend a variable amount of leading '0' charaters so that
sorting can be performed correctly.
{% endcomment %}
{% assign leading_zeros = '' %}
{% assign power = base_ten_power | minus: len_tag_frequency %}
{% for i in (1..power) %}
{% assign leading_zeros = leading_zeros | append: '0' %}
{% endfor %}
{% assign tags = tags | append: leading_zeros | append: t[1].size | append: '|' | append: t[0] | append: '§' %}
{% endfor %}
{% assign sorted_tags = tags | split: '§' | sort_natural | reverse %}
{% if site.limit_tag_links %}
{% assign s = site.limit_tag_links | plus: 0 %}
{% assign sorted_tags = sorted_tags | slice: 0, s %}
{% endif %}
<div markdown="0">
<ul>
{% for tag_elements in sorted_tags %}
{% assign tag = tag_elements | split: '|' %}
{% assign tag_name = tag[1] %}
{% assign tagg = tag_name | slugify %}
{% assign freq = tag[0] | plus: 0 %}
{% if page.is_home %}
{% if freq >= site.tag_list.score.min %}
1 year ago
{% capture link %}{{ site.baseurl }}/tags/#{{ tagg }}{% endcapture %}
<li>
<a href="{{ link }}">{{ tag_name }} [{{ freq }}]</a>
</li>
{% endif %}
{% else %}
<li>
<a href="#{{ tagg }}">{{ tag_name }}</a>
</li>
{% endif %}
{% endfor %}
</ul>
</div>