Thought it would be handy with a topic for Hugo-related “handy one liners”/scripts - that could be used as a one-time thing or incorporated into a workflow.
Here’s a couple from me. Two snippets to optimize images. Works fine in Bash:
# you will need the libjpeg-progs package to run this - note the -progressive option added
find ./static -name "*.jpg" -exec jpegtran -optimize -progressive -outfile "{}" "{}" \;
# handle pngs with pngcrush -ow > overwrite file
find ./static -name "*.png" -exec pngcrush -ow "{}" \;
Thanks @bjornerik , that optimize/crushing thingy is exactly what i was looking for!
This is what i use to cycle trough all themes installed:
for i in $(find themes/ -maxdepth 2 -iname 'theme.toml'); do \
echo -e "\nCurrent Theme: $(expr match "$i" 'themes\/\(.*\)\/theme.toml')\n"; \
hugo server --buildDrafts --watch \
--theme=$(expr match "$i" 'themes\/\(.*\)\/theme.toml'); \
done
Yes. Last time I looked, there were no native Go packages with progressive support (Go stdlib can read them, but not write them). But that may have changed already.