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.
 
 
 
 

48 lines
1.7 KiB

{% comment %} This is pure madness: an O(n^2) loop is not acceptable but
there is no other solution I am aware of using this templating
language. Using uniq to filter different frequencies should
lead to a better best case (if all frequencies are equal
we get O(n) with n being the number of tags, otherwise
if all freqencies are different we get O(n^2) {% endcomment %}
{% comment %} Get all unique tags {% endcomment %}
{% for t in site.tags %}
{% assign tag_frequency = tag_frequency | append: t[1].size | append: '#' %}
{% endfor %}
{% assign tag_frequency = tag_frequency | split: '#' %}
{% assign tag_frequency_iterator = tag_frequency | sort | reverse %}
{% assign tag_frequency = tag_frequency_iterator | uniq %}
{% for f in tag_frequency %}
{% comment %} Nice: srt to int: {% endcomment %}
{% assign freq = f | plus: 0 %}
{% for t in site.tags %}
{% if freq == t[1].size %}
{% assign sorted_tags_by_freq = sorted_tags_by_freq | append: t[0] | append: '#' %}
{% endif %}
{% endfor %}
{% endfor %}
{% assign sorted_tags_by_freq = sorted_tags_by_freq | split: '#' %}
<div class="tag-list">
<ul>
{% for tag in sorted_tags_by_freq %}
{% assign tagg = tag | slugify %}
{% if page.is_home %}
{% assign freq = tag_frequency_iterator[forloop.index0] | plus: 0 %}
{% if freq >= site.min_tag_score %}
{% capture link %}{{ site.baseurl }}/tags/#{{ tagg }}{% endcapture %}
<li>
<a href="{{ link }}">{{ tag }} [{{ freq }}]</a>
</li>
{% endif %}
{% else %}
<li>
<a href="#{{ tagg }}">{{ tag }}</a>
</li>
{% endif %}
{% endfor %}
</ul>
</div>