code and games
Built with Hugo and Hyde-Y.

Quality of Life Improvements

· Read in about 2 min · (369 Words)

In an effort to make blogging more painless, I’ve set up some conveniences.

First, per a recommendation from Hugo’s documentation, I made a deploy.sh script to make the build & upload process nice and simple.

#!/bin/sh

hugo && rsync -avz --delete public/ rackspace:/var/www/blog.zikes.me/public/

exit 0

With this, from my development machine I can run cd ~/blog.zikes.me && ./deploy.sh. The cd being necessary because hugo and rsync operate on the current working directory, not the location of the parent shell script. I was able to improve on this by getting the directory name of the shell script1.

#!/bin/sh

DIR=$(dirname "$(readlink -f "$0")")

hugo --source $DIR && rsync -avz --delete "$DIR/public/" rackspace:/var/www/blog.zikes.me/public/

exit 0

From there, I looked to clean up the HTML output of Hugo a bit. An unfortunate consequence of templates within templates is that there tends to be a lot of extra or missing indentations and line breaks. Fortunately there are tools out there already to clean up HTML. HTML Tidy made a pretty good case, so I built and installed that on my machine. I had originally installed via sudo apt install tidy, but that only has the pre-HTML5 version from 2009, which complained muchly about all the new tags. Hopefully the new version will get a Linux PPA soon.

Once I had that built I slapped together a tidy.conf file in my site root directory, mostly copied from the example in the original Tidy’s documentation2.

indent: auto
indent-spaces: 2
wrap: 0
markup: yes
output-xml: no
input-xml: no
numeric-entities: yes
quote-marks: yes
quote-nbsp: yes
quote-ampersand: no
quiet: yes
break-before-br: no
uppercase-tags: no
uppercase-attributes: no
char-encoding: utf8
new-inline-tags:
new-empty-tags:
show-warnings: no
tidy-mark: no
drop-empty-elements: no

drop-empty-elements: no was a fairly important addition to keep my Font Awesome icons in the sidebar from disappearing. After a fair amount of trial and error against individual HTML files, I added a section to my deploy script to recursively find all the HTML files built by Hugo and run Tidy against them.

#!/bin/sh

DIR=$(dirname "$(readlink -f "$0")")

hugo --source "$DIR" && \
        find "$DIR/public" -type f -name "*.html" -exec sh -c \
                "tidy -config "$DIR/tidy.conf" -m \$0" {} \; && \
        rsync -avz --delete "$DIR/public/" rackspace:/var/www/blog.zikes.me/public/

exit 0