Improve tags layout template

This commit is contained in:
Takumi Sueda 2022-12-14 02:10:52 +09:00
parent 9927d52aeb
commit c08424aa55
2 changed files with 11 additions and 9 deletions

View File

@ -19,6 +19,8 @@ layout: archive
{% endfor %} {% endfor %}
</ul> </ul>
{% comment %} Make sure that all collections are listed in the _config.yml. {% endcomment %}
{% assign entries_layout = page.entries_layout | default: 'list' %} {% assign entries_layout = page.entries_layout | default: 'list' %}
{% for label in site.collections_order %} {% for label in site.collections_order %}
{% assign collection = site.collections | where: "label", label | first %} {% assign collection = site.collections | where: "label", label | first %}

View File

@ -4,18 +4,17 @@ layout: archive
{{ content }} {{ content }}
{% assign unique_tags = "" | split: "" %} {% comment %} Flatten all documents in all categories {% endcomment %}
{% assign nested_docs = site.collections | map: "docs" %}
{% assign docs = "" | split: "" %}
{% for doc in nested_docs %} {% assign docs = "" | split: "" %}
{% assign docs = docs | concat: doc %} {% for collection in site.collections %}
{% assign docs = docs | concat: collection.docs %}
{% endfor %} {% endfor %}
{% assign found_tags = docs | map: "tags" %} {% comment %} Extract all tags {% endcomment %}
{% for tags in found_tags %} {% for doc in docs %}
{% assign all_tags = all_tags | concat: tags %} {% assign all_tags = all_tags | concat: doc.tags %}
{% endfor %} {% endfor %}
{% assign unique_tags = all_tags | uniq %} {% assign unique_tags = all_tags | uniq %}
@ -26,6 +25,7 @@ layout: archive
{% for tag in unique_tags %} {% for tag in unique_tags %}
{% comment %} Count the number of tag occurrence in all docs {% endcomment %} {% comment %} Count the number of tag occurrence in all docs {% endcomment %}
{% assign count = 0 %} {% assign count = 0 %}
{% for t in all_tags %} {% for t in all_tags %}
{% if t == tag %} {% if t == tag %}
@ -35,6 +35,7 @@ layout: archive
{% assign tags_count = tags_count | push: count %} {% assign tags_count = tags_count | push: count %}
{% comment %} Group docs by tags {% endcomment %} {% comment %} Group docs by tags {% endcomment %}
{% assign found = docs | where_exp: "item", "item.tags contains tag" %} {% assign found = docs | where_exp: "item", "item.tags contains tag" %}
{% assign tagged_docs = tagged_docs | push: found %} {% assign tagged_docs = tagged_docs | push: found %}
@ -43,7 +44,6 @@ layout: archive
{% endif %} {% endif %}
{% endfor %} {% endfor %}
<ul class="taxonomy__index"> <ul class="taxonomy__index">
{% for i in (1..tags_max) reversed %} {% for i in (1..tags_max) reversed %}
{% for tag in unique_tags %} {% for tag in unique_tags %}