Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

When setting permalink to false using Directory Data Files, exclude such items from tag collection #1251

Closed
MaybeThisIsRu opened this issue Jun 15, 2020 · 7 comments

Comments

@MaybeThisIsRu
Copy link

MaybeThisIsRu commented Jun 15, 2020

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:

  1. Have a directory called posts with blog posts written in Markdown inside it
  2. Assign tags to this post so that Eleventy makes a tag collection
  3. Create a directory data file called posts.11tydata.js
  4. Set permalink to false on some blog posts based on your own criteria
  5. Access the collection elsewhere using the collections[tag_name] syntax.
  6. Collection will include posts which have permalink set to false

Expected behavior
collections[tag_name] should exclude files that have permalink set to false.

Environment:

  • OS and Version: Pop!_OS 20.04 LTS
  • Eleventy Version: 0.11.0
@MaybeThisIsRu
Copy link
Author

@makkabi raised this issue on DEV.to as well.

@makkabi
Copy link

makkabi commented Aug 3, 2020

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.

@edwardhorsford
Copy link
Contributor

Drafts are discussed in this feature request / issue.

@hirusi for your case, you can additionally set eleventyExcludeFromCollections wherever you set permalink: false

@makkabi
Copy link

makkabi commented Aug 3, 2020

@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.

@edwardhorsford
Copy link
Contributor

@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).

Screenshot 2020-08-03 at 15 20 49

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.

@makkabi
Copy link

makkabi commented Aug 3, 2020

@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.

@zachleat
Copy link
Member

#188 is the home base for this one

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

No branches or pull requests

4 participants