{% macro render_tag(tag) -%}
    <a href="{{ SITEURL }}/{{ tag.url }}"
       class="badge text-bg-secondary"
       data-bs-toggle="tooltip"
       title="{{ tag.articles }} article{{ 's' if tag.articles > 1 else '' }} with this tag">{{ 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') %}
        {% endif %}
    {% elif protocol.startswith('http') %}
        {% set domain = link.split('%s://' % protocol, 1)[1].split('/', 1)[0] %}
        {% set SITE_ICONS = {
        'apple': ['apple.com']
        , 'bitbucket': ['bitbucket.org', 'bitbucket.com']
        , 'dropbox': ['dropbox.com']
        , 'facebook-square': ['facebook.com']
        , 'github': ['github.com']
        , 'hacker-news': ['news.ycombinator.com']
        , 'linkedin': ['linkedin.com']
        , 'stack-overflow': ['stackoverflow.com']
        , 'stack-exchange': ['stackexchange.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="fab {{ 'fa-%s' % icon[0] }} fa-fw"></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="fas fa-external-link-alt fa-fw"></i>
        {% endif %}
        {{ label }}
    </a>
{%- endmacro %}
