{% extends "base.html" %}
{% block title %}All categories{% endblock title %}
{% block top_center %}
    <h1>
        <a href="{{ SITEURL }}/{{ CATEGORIES_SAVE_AS }}"
           rel="bookmark"
           title="Permalink to category list">Categories</a>
    </h1>
{% endblock top_center %}
{% block content %}
    {% set all_categories = [] %}
    {% for category, articles in categories %}
        {% if all_categories.append({'name': category.name, 'url': category.url, 'articles': articles|length()}) %}{% endif %}
    {% endfor %}
    <dl class="row">
        {# Sort by category frequency, then alphabetically #}
        {% for category in all_categories|sort(attribute='name')|sort(reverse=True, attribute='articles') %}
            <dt class="col-sm-2">
                <a href="{{ SITEURL }}/{{ category.url }}" class="badge category">{{ category.name }}</a>
            </dt>
            <dd class="col-sm-10">
                <a href="{{ SITEURL }}/{{ category.url }}">{{ category.articles }} article{{ 's' if category.articles > 1 else '' }}</a>
            </dd>
        {% endfor %}
    </dl>
{% endblock content %}
