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


#1

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?


#2

Use a text editor.


#3

Here’s what I use:

#!/bin/sh
file=content/$1
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
else
    echo "$file not found"
    exit 1
fi
exit 0

#4

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


#5

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/undraft.sh 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.

-j


#6

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.


#7

I agree. Thank you for your reply.