Use the same template for taglists and the blog index. Move the tagposts into a collection to make life easier
Build and copy to prod / build-and-copy (push) Successful in 2m7s

This commit is contained in:
Lewis Dale committed 2024-04-12 10:15:25 +01:00
1 parent 2a900ce835
commit d209f82688
7 files changed
+71 -58

No files matched your search

+24 -4
View File
@@ -1,10 +1,30 @@
module.exports = (eleventyConfig) => {
eleventyConfig.addCollection('tags', (collectionApi) => {
const tags = new Set();
collectionApi.getAll().forEach((item) => {
if (!item.data.tags) return;
item.data.tags.forEach((tag) => tags.add(tag));
});
collectionApi.getFilteredByTag("posts")
.filter(p => process.env.DEBUG || !p.data.tags.includes("draft"))
.filter(p => process.env.DEBUG || p.date < new Date())
.forEach((item) => {
if (!item.data.tags) return;
item.data.tags.forEach((tag) => tags.add(tag));
});
return [...tags];
});
eleventyConfig.addCollection('tagPosts', (collectionApi) => {
const tagPosts = {};
collectionApi.getFilteredByTag("posts")
.filter(p => process.env.DEBUG || !p.data.tags.includes("draft"))
.filter(p => process.env.DEBUG || p.date < new Date())
.forEach((item) => {
if (!item.data.tags) return;
item.data.tags.forEach((tag) => {
if (!(tag in tagPosts)) {
tagPosts[tag] = [];
}
tagPosts[tag] = [item, ...tagPosts[tag]];
});
});
return tagPosts;
});
}