-
-
Save tannerdolby/0fd575a480d0299e1d6735f462799d77 to your computer and use it in GitHub Desktop.
@seezee Can you provide an example use case you're thinking of? If I understand correctly, you are looking to disallow certain tags when using the taglist
filter.
Option 1:
If you know the tags you don't want the filter to output, you could provide a disallow list and then filter out disallowed tags before returning the sorted list.
eleventyConfig.addFilter("taglist", function(collection) {
const disallowed = ["foo", "bar"];
const tags = [];
collection.forEach(post => {
tags.push(...post.data.tags);
});
const sorted = [...new Set(tags)]
.filter((tag) => !disallowed.includes(tag))
.sort((a, b) => a.localeCompare(b));
return sorted;
});
Option 2:
Filter the tags you don't want the filter to process ahead of time before utilizing the taglist
filter.
@seezee Can you provide an example use case you're thinking of? If I understand correctly, you are looking to disallow certain tags when using the
taglist
filter.Option 1: If you know the tags you don't want the filter to output, you could provide a disallow list and then filter out disallowed tags before returning the sorted list.
eleventyConfig.addFilter("taglist", function(collection) { const disallowed = ["foo", "bar"]; const tags = []; collection.forEach(post => { tags.push(...post.data.tags); }); const sorted = [...new Set(tags)] .filter((tag) => !disallowed.includes(tag)) .sort((a, b) => a.localeCompare(b)); return sorted; });Option 2: Filter the tags you don't want the filter to process ahead of time before utilizing the
taglist
filter.
That worked a treat! Thank you!
Glad to hear it. You're welcome!
Was looking for a way to just generate a simple alphabetized list of my tags to use as a reference to keep track of my own posting mess, and this works perfectly for that and was extremely well explained. Thank you so much!
How would one filter specific tags so they aren't picked up by this filter?