I am curious if you can explain why you are using csv data? While I am sure you have your use case, you could search through all available tags and provide links to posts. You can find code to do this here in the official Jekyll docs.
That said, I think what you want is to look at all the tags in a csv file and then display what posts contain those tags, correct? Below is an example
CSV data
Here is a basic data CSV data set containing the tags we care about. Since Jekyll treats any space between each tag in tags
, create add a display-friendly label:
/_data/tag-data.csv
title,label
pets,Cute pets
wildanimals,Wild animals
fish,Fish and dolphins
Three sample posts
In my example, I created three posts in Jekyll, with YAML front matter, each using a variation of tags.
First post
/_posts/2023-04-03-first-post.markdown
---
layout: post
title: "First post"
date: 2023-04-05
tags: fish wildanimals
---
Some content...
Second post
/_posts/2023-04-04-second-post.markdown
---
layout: post
title: "Second post"
date: 2023-04-04
tags: pets fish
---
Some content...
Third post
/_posts/2023-04-05-third-post.markdown
---
layout: post
title: "Third post"
date: 2023-04-05
tags: pets
---
Some content...
Code
From here, we can read the list of tags from /_data/tag-data.csv
and then list all the posts that contain a match.
/tags-from-csv.markdown
---
layout: default
---
## List of posts that match the tag-data.csv file
{%- assign tagData = site.data.tag-data -%}
{% for tag in tagData %}
<dl>
<dt><strong>Tag: </strong>{{tag.label}} ({{tag.item}})</dt>
{%- assign posts = site.posts | where_exp: "item", "item.tags contains tag.item" -%}
{% for post in posts %}
<dd>- <a href="{{ post.url | relative_url }}">{{ post.title }}</a></dd>
{% endfor %}
</dl>
{% endfor %}
The output for the code will look something like this:
Hope this helps!