-
-
Save jensgro/3ef351c4049cde6dc1dc45312725f02a to your computer and use it in GitHub Desktop.
custom eleventy filter to count posts by year #eleventy #ssg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
eleventyConfig | |
.addFilter('yearTags', posts => { | |
const yearsList = posts.map(p => p.data.date.getFullYear()) | |
const yearsCount = {} | |
yearsList.forEach(y => { | |
if (!yearsCount[y]) yearsCount[y] = 1 | |
else yearsCount[y]++ | |
}); | |
return Object.keys(yearsCount) | |
.map(yc => ({ name: yc, count: yearsCount[yc] })) | |
}); | |
//... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment