eleventy
eleventy copied to clipboard
Make eleventyExcludeFromCollections pages still accessible for custom collections
Is your feature request related to a problem? Please describe.
I have a few types of pages that I currently exclude from collections because I want them to disappear across the site (including sitemap, tag pages, lists of posts). Drafts are my main use case, but I also have a few test posts for checking markup and deleted pages are generated with a stub but otherwise should disappear.
However, I still want to access the drafts and test pages. I currently have to manually curate a drafts page, and I can't use test pages in some tests because I can't get the page data.
Describe the solution you'd like
I would like a collection of only the excluded pages.
eleventyConfig.addCollection('testPosts', (collection) => collection
.getExcluded()
.filter((page) => page.data.eleventyExcludeFromCollections == 'test')
);
I'd prefer if using a string as the eleventyExcludeFromCollections would automatically group them but that feels a little out of scope.
{% for posts in collections.excluded.test %}
Describe alternatives you've considered
I've considered not setting eleventyExcludeFromCollections and doing filtering elsewhere, but this has some problems.
- Would not apply to tag collections, so those would need to be filtered, which is hard with pagination
- Custom collections would need to be filtered after glob
- Would need to maintain a new "all" with filtering
- It would be harder to manage all these filters and would be easy to miss something
- Still would need new collections for my test and draft posts
Additional context
I've also looked at #1175 but I don't think that would work as I still don't want content on the tag pages.
I personally think that this could be solved with #955, as you could move all draft posts in a seperate layer under a drafts collection.
I'd personally recommend against a collection called "excluded" that includes the excluded pages (this sentence is hard, I know), but instead recommend adding a new excludedFromCollections variable next to collections.
So instead of
{% for posts in collections.excluded.test %}
you'd use
{% for posts in excludedFromCollections.test %}
That way you could still create a collection called "excluded" as a user.
Naming to be discussed.
What I did in the past to resolve this, was often changing the collection to "hidden_test" so they are actually moved into a separate collection, but that's also not ideal and breaks with directory data files that apply collections.
That possibly could work but wouldn't be ideal as it would still require remembering to filter this content elsewhere in my site. I still want all this content excluded from everywhere (main posts list, tag pages, sitemap, etc). I only want to opt-in to accessing these pages on my draft view.