{% macro render_tag(tag, counter, kind='tag') -%}
    {# A tag or a category can be pass as argument as they share the same data structure #}
    {% set kind = 'tag' if kind == 'tag' else 'category' %}
    <a href="{{ SITEURL }}/{{ tag.url }}"
       rel="tag"
       class="badge {{ kind }}"
       data-bs-toggle="tooltip"
       {% if counter is defined %} title="{{ counter }} article{{ 's' if counter > 1 else '' }} with this {{ kind }}" {% endif %}>{{ tag.name }}</a>
{%- endmacro %}
{% macro render_link_icon(link, label, favicon=True) -%}
    {% set icon = [] %}
    {% set favicon = False if favicon == False else True %}
    {% set protocol = link.split(':', 1)[0] %}
    {% if protocol == 'mailto' %}
        {% if icon.append('envelope-fill') %}{% endif %}
    {% elif protocol.startswith('http') %}
        {% set domain = link.split('%s://' % protocol, 1)[1].split('/', 1)[0] %}
        {% set SITE_ICONS = {
            "apple": [
                "apple.com"
            ],
            "dropbox": [
                "dropbox.com"
            ],
            "facebook": [
                "facebook.com"
            ],
            "github": [
                "github.com"
            ],
            "linkedin": [
                "linkedin.com"
            ],
            "stack-overflow": [
                "stackexchange.com",
                "stackoverflow.com"
            ],
            "twitter": [
                "twitter.com"
            ],
            "youtube": [
                "youtube.com"
            ]
        } %}
        {% for (site_icon, site_domains) in SITE_ICONS.items() %}
            {% for site_domain in site_domains %}
                {% if domain.startswith(site_domain) %}
                    {% if icon.append(site_icon) %}{% endif %}
                {% endif %}
            {% endfor %}
        {% endfor %}
    {% endif %}
    <a href="{{ link }}">
        {% if icon %}
            <i class="bi {{ 'bi-%s' % icon[0] }}"></i>
        {% elif domain and favicon %}
            <img src="https://www.google.com/s2/favicons?domain={{ domain }}"
                 width="16"
                 height="16"
                 class="link-icon"
                 alt="{{ domain }} icon" />
        {% else %}
            <i class="bi bi-box-arrow-up-right"></i>
        {% endif %}
        {{ label }}
    </a>
{%- endmacro %}
