Any way to detect if hugo was launched with --buildDrafts?

I’d like to detect if hugo was launched with --buildDrafts so that I can enable disable other things besides full content files, e.g. I may want to add some buttons or sections within a layout. is there a variable that gets set telling me if hugo was launched with --buildDrafts or not?


Not a direct response, more a hack, but you can :

1 - Add a parameter in your config.toml : buildDrafts = true/false
2 - Have shortcodes/partials with this logic :

{{ if site.Params.buildDrafts }}
 ... do your draft stuff ...
{{ end }}

3 - And instead of turning on/off from calling hugo, do it by updating your conf file.

Indeed, and I was aware of the workarounds, but it made more sense to leverage existing functionality around draft: true and hugo -D.

p.s. Unrelated: It would have been nicer to have the draft flags in config.yaml (as an array) than a bool in each content file … would make them available everywhere (e.g. some page being draft implies killing/activating some menu entry in the header, etc).