11ty / eleventy-base-blog

A starter repository for a blog web site using the Eleventy static site generator.

Home Page:https://eleventy-base-blog.netlify.app/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simplify getAllTags filter?

flachware opened this issue · comments

Apologies if I’m missing something – for rendering the tag list, wouldn’t it be more straightforward to simply use the keys of the collections object instead of creating an array out of collections.all?

<!-- tags-list.njk -->
{% for tag in collections.all | getAllTags | filterTagList %}

<!-- eleventy.config.js -->
// Return all the tags used in a collection
eleventyConfig.addFilter("getAllTags", collection => {
let tagSet = new Set();
for(let item of collection) {
	(item.data.tags || []).forEach(tag => tagSet.add(tag));
}
return Array.from(tagSet);
});

Could be:

<!-- tags-list.njk -->
{% for tag in collections | getAllTags | filterTagList %}

<!-- eleventy.config.js -->
// Return all the tags used in collections
eleventyConfig.addFilter("getAllTags", collections => {
  return Object.keys(collections);
});

Yeah, that’s true and a fair point!

The currently implementation of getAllTags has the potential for wider general purpose use, though?

Right, if there is a need to get all tags of a specific collection I can understand that approach. Thanks for clarifying.

This is an automated message to let you know that a helpful response was posted to your issue and for the health of the repository issue tracker the issue will be closed. This is to help alleviate issues hanging open waiting for a response from the original poster.

If the response works to solve your problem—great! But if you’re still having problems, do not let the issue’s closing deter you if you have additional questions! Post another comment and we will reopen the issue. Thanks!