-
|
I followed the instructions and managed to do it how I like it to implement a tag system. function filterTagList(tags) {
return (tags || []).filter(tag => ["all", "nav", "post", "posts"].indexOf(tag) === -1);
}
eleventyConfig.addFilter("filterTagList", filterTagList)
// Create an array of all tags
eleventyConfig.addCollection("tagList", function(collection) {
let tagSet = new Set();
collection.getAll().forEach(item => {
(item.data.tags || []).forEach(tag => tagSet.add(tag));
// (item.data.keywords || []).forEach(keyword => tagSet.add(keyword));
});
return filterTagList([...tagSet]);
});those tags/keywords would be renderer in tag pages |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
Good news, I think your When you set
---
# src/index.njk
pagination:
# 1
data: collections.tagList
size: 1
# 2
alias: tag
permalink: /tags/{{ tag | slugify }}/
---
<h1>Tagged « {{ tag }} »</h1>
<ol>
<!-- 3 -->
{% set taglist = collections[ tag ] %}
{% for note in taglist | reverse %}
<li><a href="{{ note.url }}">{{ note.data.title }}</a></li>
{% endfor %}
</ol>
<!-- 4 -->
{{ collections.tagList | dump(2) | safe }}OUTPUT<h1>Tagged « animal »</h1>
<ol>
</ol>
[
"fruit",
"vegetable",
"animal",
"mineral"
]So our If you have to use |
Beta Was this translation helpful? Give feedback.
Good news, I think your
(item.data.keywords || []).forEach(keyword => tagSet.add(keyword));code is correct.Bad news, I don't think that works.
When you set
tagsin your front matter (or data file), it will automatically create a matchingcollections.<tag>collection for you.If you use a different front matter key (like
keywords) it won't.So in my simplified test case (based on your code above), we…:
collections.tagList(which was defined in the .eleventy.js config file)tagcollections[tag](which will not work since we are usingkeywordsalias in front matter instead oftags){{ collections.tag…