I accidentally removed draft = true line in the front matter which caused the unfinished post being built and deployed live. I couldn’t find a way to stop Hugo from publishing content that doesn’t have a draft parameter, as Hugo sees that as draft = false.
So I created a Bash script to check before running hugo and fails the build if there’s any content that does not have either draft = true (skip/default behaviour) or draft = false (pass/ok). It will triggers a fail + error message.
A relevant Discourse post I came across was this one but I couldn’t get the cascade to work (or it didn’t work for my setup) and the whitelisting method is not available by default.
The script can be found in my Codeberg Repo. I go into detail about how I use it in a blog post. Feedback welcome.
I hope this helps because I did not enjoy the mistake of publishing a draft and hope no one has to go through it either!
Thanks @irkode for explaining with your example on how to use the cascade. I tried using the snippet from issue in 2023 ( How to set all md files front matter draft false default ,in config file or other method? - #4 by jmooring ) before I created the script but I could not get it to work reliably (sometimes a .md will still be published when it didn’t have the draft parameter). I think I’ll start using the cascade snippet in my Hugo config and add a section to the blog post I wrote, and use the external script as a fallback for edge cases. Thank you so much!