{% capture rawtags %}{% for doc in include.items %}{% for tag in doc.tags %}{{ tag }} {% endfor %}{% endfor %}{% endcapture %}

{% assign tags = rawtags | split: “ ” | uniq %} {% assign num_tags = tags | size %}

{% if include.tag %}

{% if include.tag contains ":" %}
  {% assign tag_namespace = include.tag | split: ":" | first %}
{% else %}
  {% assign tag_namespace = "" %}
{% endif %}

{% endif %}

{% if num_tags > 0 %}

<nav class="item-filter">
  {% comment %}Non-namespaced tags{% endcomment %}
  <ul class="tags">
    {% for tag in tags %}
      {% if tag contains ":" %}
        {% assign _namespace = tag | split: ":" | first %}
      {% else %}
        {% assign _namespace = "" %}
      {% endif %}

      {% if _namespace == "" %}
        <li>
          {% assign tag_human = tag | replace: "_", " " %}
          {% if tag == include.tag %}
            <span>{{ tag_human }}</span>
          {% else %}
            <a href="{{ include.url_tag_prefix }}{{ tag }}">{{ tag_human }}</a>
          {% endif %}
        </li>
      {% endif %}
    {% endfor %}
  </ul>

  {% comment %}Namespaced tags{% endcomment %}
  {% for namespace in site.tag_namespaces[include.tag_namespaces] %}
    {% assign namespace_human = namespace[1] %}
    {% assign namespace_id = namespace[0] %}

    <div class="namespace">
      <span class="namespace-title">{{ namespace_human }}: </span>

      <ul class="tags">
        {% for tag in tags %}
          {% if tag contains ":" %}
            {% assign _namespace = tag | split: ":" | first %}
          {% else %}
            {% assign _namespace = "" %}
          {% endif %}

          {% if _namespace == namespace_id %}
            <li>
              {% assign tag_human = tag | split: ":" | last | replace: "_", " " %}
              {% if tag == include.tag %}
                <span>{{ tag_human }}</span>
              {% else %}
                <a href="{{ include.url_tag_prefix }}{{ tag }}">{{ tag_human }}</a>
              {% endif %}
            </li>
          {% endif %}
        {% endfor %}
      </ul>
    </div>
  {% endfor %}
</nav>

{% endif %}

{% if include.tag %}

{% assign tag_human = include.tag | split: ":" | last | replace: "_", " " %}
{% if tag_namespace != "" %}
  {% assign namespace = site.tag_namespaces[include.tag_namespaces][tag_namespace] %}
{% endif %}
<header class="filter-header">
  <h3 class="title">
    Showing items matching
    <span class="tag">{% if namespace %}<span class="namespace">{{ namespace }}:</span> {% endif %}{{ tag_human }}</span>
    <a class="show-all" href="{{ include.url_tag_prefix }}">(show all)</a>
  </h3>
</header>

{% endif %}