Open thoresson opened 3 months ago
The original code if(data.draft && !process.env.BUILD_DRAFTS)
uses data.draft
in a boolean context, which means that Javascript evaluates whether or not its value is truthy, that is, anything that is not falsy.
Using YAML front matter, the following values for draft
are falsy:
draft: false # boolean false
draft: 0 # numeric zero
draft: "" # empty string
draft: null # no value
Just about everything else is truthy, including:
draft: true # boolean true
draft: 1 # non-zero number
draft: -1 # non-zero number
draft: "true" # non-empty string
draft: "false" # non-empty string
draft: "no" # non-empty string
draft: no # non-empty string (In YAML, this is the same as the line before)
Maybe double-check that draft
isn't set to something that is being treated as a string.
Since I'm new both to JS and Eleventy, it might be that I'm missing something. But when I couldn't get drafts working as I expected, I dived into the draft functions and found that there is only checks for wether draft is defined in the frontmatter or not. According to the docs, "draft: true" should exclude drafts from the builds, but any post where draft is defined is actually omitted.
This gave me the behaviour I was expecting.
Sorry if I'm missing something obvious here! :)