{% extends "base.html" %} {% block title %} All tags {% endblock %} {% block top_center %}

Tags

{% endblock %} {% block content %} {% set all_tags = [] %} {% for tag, articles in tags %} {% if all_tags.append({'name': tag.name, 'url': tag.url, 'articles': articles|length()}) %}{% endif %} {% endfor %} {% set tier_1 = [] %} {% set tier_2 = [] %} {% set tier_3 = [] %} {% set total_tags = all_tags|sum(attribute = 'articles') %} {# Sort by tag frequency, then alphabetically #} {% for tag in all_tags|sort(attribute='name')|sort(reverse=True, attribute='articles') %} {% if tier_1|sum(attribute = 'articles') < total_tags / 3.0 or tier_1[-1].articles == tag.articles %} {% if tier_1.append(tag) %}{% endif %} {% elif tier_2|sum(attribute = 'articles') < total_tags / 3.0 or tier_2[-1].articles == tag.articles %} {% if tier_2.append(tag) %}{% endif %} {% else %} {% if tier_3.append(tag) %}{% endif %} {% endif %} {% endfor %} {% for (tier_name, tier_tags) in [("Top", tier_1), ("Middle", tier_2), ("Lower", tier_3)] %}

{{ tier_name }} tier

{% for tag in tier_tags %} {{ m.render_tag(tag) }} {% endfor %}

{% endfor %} {% endblock %}