11ty / eleventy-base-blog

A starter repository for a blog web site using the Eleventy static site generator.
https://demo-base-blog.11ty.dev/
MIT License
1.23k stars 619 forks source link

Simplify getAllTags filter? #145

Closed flachware closed 1 year ago

flachware commented 1 year ago

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);
});
zachleat commented 1 year ago

Yeah, that’s true and a fair point!

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

flachware commented 1 year ago

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

zachleat commented 1 year ago

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!