Skip to content

Instantly share code, notes, and snippets.

@jensgro
Forked from tannerdolby/sort-tags.js
Created February 10, 2023 19:52
Show Gist options
  • Save jensgro/73291c0c43f80edb8f9324996ea8236c to your computer and use it in GitHub Desktop.
Save jensgro/73291c0c43f80edb8f9324996ea8236c to your computer and use it in GitHub Desktop.
11ty filter for returning a sorted list of tags from collections. Use the it in a template like {{ collections.foo | taglist }} to get the sorted tag list.
eleventyConfig.addFilter("taglist", function(collection) {
const tags = [];
collection.forEach(post => {
tags.push(...post.data.tags);
});
const sorted = [...new Set(tags)].sort((a, b) => a.localeCompare(b));
return sorted;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment