How to touch the date after `undraft` is deleted?

In gohugoio/hugo#4354, the command undraft is deleted. This command can delete draft = true and update the date to the current time.
It is easy to delete draft = true by hande. But how to update date from CLI?

Use a text editor.

1 Like

Here’s what I use:

now=$(date "+%Y-%m-%dT%H:%M:%S%z" | sed -e 's/00$/:00/')

if [ -f $file ]; then
    mv $file $file-
    sed -e 's/^date *= *"20.*"$/date = "'$now'"/' \
        -e 's/^draft *= *true//' < $file- > $file
    echo "$file not found"
    exit 1
exit 0

Thanks for your solution.
But it is still a pity that hugo can not do it directly.

I disagree. I can come up with all sorts of things that could be built into Hugo, but implementing them so that they’d be useful for a variety of workflows takes time away from robust core features and solid documentation. I’d rather see a simple plug-in system that looked up unknown commands in a portable way (say, plugin/ on Mac/Linux, plugin/undraft.bat on Windows).

Maybe your undraft sets the date to now, maybe mine sets it to match publishDate if that’s present, maybe someone else’s sets weight for featured articles or adds lastmod to preserve the original timestamp, etc, etc. A built-in would support only one option.


Adding the undraft command might have been an … OK idea at some point.

But when I kept on having to maintain it (fixing it when I or someone else broke it), it was not worth it.

So, non-core and nice-to-have features will only be added if they are cheap (to implement and maintain). And I will continue to remove them when they take too much of my time.


I agree. Thank you for your reply.