Skip to content

Conversation

@pdehaan
Copy link

@pdehaan pdehaan commented Aug 27, 2021

No description provided.

Comment on lines +11 to +16
eleventyConfig.addFilter("head", (arr = [], idx = 0) => {
if (idx < 0) {
return arr.slice(idx);
}
return arr.slice(0, idx);
});
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably ignore this. I think it was from the index.njk and was throwing errors saying there wasn't a "head" filter, so I took a random guess. But then ended up using Nunjucks comments to comment out those code blocks anyways.

Comment on lines +18 to +22
eleventyConfig.addFilter("tagsList", (arr = []) => {
const tagsSet = new Set();
arr.forEach((item) => item.data.tags?.forEach((tag) => tagsSet.add(tag)));
return [...tagsSet].sort((b, a) => b.localeCompare(a));
});
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is basically the same logic as your custom collection, except for as a filter; so now you can pass a custom collection.

// return [...tagsSet].sort((b, a) => b.localeCompare(a))
// });

// https://www.11ty.dev/docs/copy/#manual-passthrough-file-copy-(faster)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can ignore all these changes below. I think I ran prettier against the input/output and it probably fixed the indenting here.

<!--
TO DO
{# TO DO
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used a Nunjucks comment so that it wouldnt try compiling the code below (see previous note about missing head filter).

<!-- PROBLEM -->
<!-- outputs tags. Should be all tags for collection.sights only, but outputs also all collections.sounds tags - I don't want this to happen and I have to find a solution -->
{% for tag in collections.tagsList %}
{% for tag in collections.sights | tagsList %}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So instead of using collections.tagsList (which uses .getAll() and getting sights+sounds) I can use the new custom tagsList filter to just generate a tag list for the "sights" collection specifically.

<!-- PROBLEM -->
<!-- outputs tags. Should be all tags for collection.sounds only, but outputs also all collections.sights tags - I don't want this to happen and I have to find a solution -->
{% for tag in collections.tagsList %}
{% for tag in collections.sounds | tagsList %}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above re "collections.sights" and custom tagsList filter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant