Describe the bug
I use a directory data file to set blog posts or pages to permalink: false to exclude them from build on production, if the file is marked as a draft in my Git-based CMS.
The files marked as draft: true correctly get assigned the computed property of permalink: false. However, if accessing the collection using the following syntax, they are still included in this collection:
{% for article in collections[tag_name] reversed %}
// do something
{% endfor %}
As a temporary workaround, I also check the permalink value manually:
{% for article in collections[tag_name] reversed %}
{% if article.url != false %}
// do something
{% endif %}
{% endfor %}
To Reproduce
Steps to reproduce the behavior:
posts with blog posts written in Markdown inside itposts.11tydata.jspermalink to false on some blog posts based on your own criteriacollections[tag_name] syntax.Expected behavior
collections[tag_name] should exclude files that have permalink set to false.
Environment:
@makkabi raised this issue on DEV.to as well.
I think there are usecases where you want to set permalink to false, but still NOT exclude the content from collections. For example, you could have a folder with "testimonials", and while you don't want to generate single pages for every testimonial (which you can do by setting permalink to false), you still want to have a collection with all testimonials, so you can display them on e.g. your frontpage.
So not automatically excluding content without permalink is not a bug, but a useful feature. I think a draft status, which completely excludes content in the production build, should be separate from the permalink setting.
It would be great if the docs would include a description how to implement "drafts" in an easy way. (By easy I mean without e.g. GIT features like draft branches, which may be too complicated for many users.)
Even better would be a native draft feature in eleventy, e.g. just setting "draft" to true in frontmatter.
Drafts are discussed in this feature request / issue.
@hirusi for your case, you can additionally set eleventyExcludeFromCollections wherever you set permalink: false
@edwardhorsford Thanks! If you would not set eleventyExcludeFromCollections directly to false, but use eleventyComputed to either set it to true or false, based on whether there is a frontmatter of draft: true AND you are in production mode. If you then also use eleventyComputed to set permalink to false, as described by @hirusi in her dev.to post, you pretty much have a draft status feature.
@makkabi
Here's how I use them - I reference a env var that determines whether they're true or not - no need for eleventyComputed (which didn't exist when I was working on these pages).

I would say they're not quite a substitute for draft. Even with eleventyExcludeFromCollections, eleventy _still_ processes the file. In my case, some of my templates are very costly to process. So even though they have permalink: false and eleventyExcludeFromCollections: true, they still take ages to be processed. In the end I've had to manually add them to eleventyIgnore to work around this.
@edwardhorsford Thanks! In the end all the discussed solutions are workarounds for a very basic feature, and I hope that 11ty will soon have a built-in (and optimized) way to do this.
Most helpful comment
@edwardhorsford Thanks! In the end all the discussed solutions are workarounds for a very basic feature, and I hope that 11ty will soon have a built-in (and optimized) way to do this.