Hugo

Handy one-liners

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 "{}"  \;
4 Likes

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
1 Like

Digging this old tip & trick …

I can’t find any option for doing the -progressive option in “new” Hugo images processing options

I guess this is a limitation of the underlying Go package ?

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.