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
Build and copy to prod / build-and-copy (push) Successful in 2m7s
This commit is contained in:
1 parent
2a900ce835
commit
d209f82688
7 files changed
+71
-58
No files matched your search
@@ -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;
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user