I have a website built around three ‘collections’. Each page of the collection will have some keywords, and I would like to create a page (outside the collection) that collects the keywords together, so, e.g., makes a list of the keywords, like this:
Keywords
- key word 1
- hyper link to page A: Page A uses keyword 1
- hyper link to page E: Page E uses key word 1
- key word 2
- hyper link to page A: page A uses keyword 2
- hyper link to page B: page B uses keyword 2
- hyper link to page G: page G uses keyword 2
- key word 3
…
and so on.
An additional complication is that there are three different collections containing the pages I want to parse in this way, but I want to make a single list of keywords of this kind that ‘stiches together’ all three collections.
I started out by putting some sample keywords in the YAML headers of the first few pages of one of the three collections (collection named GPI_chapters
) and tried the following code, from a Stack Overflow answer to build this page, but it’s quite inadequate.
{% assign tags = site.GPI_chapters | map: 'keywords' | uniq %}
{% for tag in tags %}
<h3>{{ tag }}</h3>
{% for page in site.GPI_chapters %}
{% if page.keywords contains tag %}
<a href="{{site.baseurl}}{{page.url}}">{{ page.title }}</a>
{% endif %}
{% endfor %}
{% endfor %}