# Bash script checker to prevent drafts from being published accidentally

**URL:** <https://discourse.gohugo.io/t/bash-script-checker-to-prevent-drafts-from-being-published-accidentally/57238>\
**Category:** tips & tricks\
**Tags:** frontmatter\
**Created:** [June 4, 2026, 9:30am UTC](https://discourse.gohugo.io/t/bash-script-checker-to-prevent-drafts-from-being-published-accidentally/57238 "2026-06-04T09:30:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ES7313](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/es7313/32/25973_2.png) [@ES7313](https://discourse.gohugo.io/u/ES7313)\
**Post date:** [June 4, 2026, 9:30am UTC](https://discourse.gohugo.io/t/bash-script-checker-to-prevent-drafts-from-being-published-accidentally/57238/1 "2026-06-04T09:30:58Z")

</div>

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](https://discourse.gohugo.io/t/how-to-set-all-md-files-front-matter-draft-false-default-in-config-file-or-other-method/30854/2) 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](https://codeberg.org/burgeonlab/gists/src/branch/main/hugo/check-draft-status). I go into detail about how I use it in a [blog post](https://burgeonlab.com/blog/pre-hugo-build-draft-status-checker/). 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!

---

<div class="post-metadata">

**Author:** ![irkode](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/irkode/32/26135_2.png) [@irkode](https://discourse.gohugo.io/u/irkode)\
**Post date:** [June 4, 2026, 3:13pm UTC](https://discourse.gohugo.io/t/bash-script-checker-to-prevent-drafts-from-being-published-accidentally/57238/2 "2026-06-04T15:13:48Z")

</div>

mmh,

but the cascade option works fine (as stated in the issue targets pages only

```toml
[[cascade]]
[cascade.params] 
draft = true
[cascade.target] # _target deprecated in 156
kind = 'page'

```

of course only may need to adjust the targets depending on config and folders …

unless you have very special stuff, no need for external script

> **some details tl;tr**
>
> ```auto
> hugo new theme --themesdir drafts
> cd drafts/content
> # duplicate posts
> cp -r posts blogs
> 
> ```
> 
> - Builds 23 pages
> - `hugo list drafts` returns none
> 
> all posts have set drafts to false, so: I removed three (shown just the drafts)
> 
> ```plaintext
> ├───blogs
> │ └───post-3
> │ bryce-canyon.jpg
> │ index.md <-- draft
> └───posts
> │ post-1.md <-- draft
> │ post-2.md <-- draft
> 
> ```
> 
> added the cascade to sites config
> 
> - build 20 Pages
> 
> - hugo list drafts returns three
> 
> a build guard could then be be `wc -l` respecing hugo settings like renderSegments, …

---

<div class="post-metadata">

**Author:** ![ES7313](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/es7313/32/25973_2.png) [@ES7313](https://discourse.gohugo.io/u/ES7313)\
**Post date:** [June 9, 2026, 3:08am UTC](https://discourse.gohugo.io/t/bash-script-checker-to-prevent-drafts-from-being-published-accidentally/57238/3 "2026-06-09T03:08:01Z")

</div>

> [@irkode](#):
>
> details tl

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](https://discourse.gohugo.io/t/how-to-set-all-md-files-front-matter-draft-false-default-in-config-file-or-other-method/30854/4) ) 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!
