Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Make eleventyExcludeFromCollections pages still accessible for custom collections #3078

Open
aciccarello opened this issue Oct 25, 2023 · 3 comments

Comments

@aciccarello
Copy link

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.

@Snapstromegon
Copy link
Member

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.

@aciccarello
Copy link
Author

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.

@danburzo
Copy link
Contributor

danburzo commented Nov 30, 2024

I’ve landed on this limitation when trying to HTTP 301 my RSS feed (which is excluded from collections) to a different location. I’ve been gathering aliases properties from pages to collate into one big .htaccess:

	config.addCollection('aliases', data => {
		return data.getAll().map(
			it => (it.data.aliases || [])
				.map(alias => {
					return { 
						from: alias.replace(/^\/|\/$/g, ''), 
						to: it.url 
					};
				})
		).flat();
	});

But the RSS feed page understandably is not picked up by this routine. It would be great to be able to concatenate excluded pages to the all collection.

Perhaps a good API insertion point would be in the collections API, in the form of getAll(include_excluded: true), or a clearer getExcluded() method as suggested before.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants