~/blog/"My website building workflow"

2022-03-27


This website has not existed for long, but I feel like I should share how I build it.

As mentioned on the intro post, I’m using a static website engine written in Rust called zola. It builds a website based on a bunch of markdown files (one for each page), and stores the final result in a directory called public/, along with any files that you might have (e.g. images).

I’m a pretty big proponent of getting rid of bloat, so the default output is just not good enough. However, what people consider bloat is relative (one man’s bloat is another man’s essential feature), so I’ll stick with a definition we can all agree on: any data that does not change the users’ experience, and just drags down performance.

One very easy way of getting rid of useless website data is to just minify minify the HTML, which zola supports by setting minify_html = true in the config.toml file.

Another way of reducing the amount of data (and to increase privacy as well), is to get rid of metadata in your files. For this task, I use mat2; which is able to clean the metadata from a variety of filetypes, including: images, audio, video, etc.

To bring all of this together, I have a very simple script that is run to build the release version of this website:

# Build website
zola build
# Clean all metadata from images that are going to be uploaded
mat2 --inplace $(find public/ -type f -exec file {} \; | awk -F: '{ if ($2 ~/[Ii]mage|EPS/) print $1}')

The first line is pretty self-explanatory.

The second line lists all the files in the public/ directory (find public/ -type f -exec file {} \;), filters out just the paths to images (awk -F: '{ if ($2 ~/[Ii]mage|EPS/) print $1}'), and then passes those as inputs to mat2, which proceeds to clean the metadata inplace.

Hopefully you can take some ideas on how to make your own website lighter, without changing a single thing regarding its appearance, or the quality of the images.