Improving My Blog Post Publishing Script

Written By: Jake Bauer | Posted: 2020-06-11 | Last Updated: 2020-06-11

Like I previously did to my website compilation script, today I rewrote the script I use to publish posts to my website and syndicate those posts to Mastodon. It was about time since that script was a long list of commands with no functions, few clear variables, and written in Bash instead of POSIX shell code.

Thanks to the work I did for my compilation script, I could copy much of the structure and some functions over to the new publish script. The lessons I learned in making the compilation script portable also meant that I already had the skills and knowledge necessary to make the publish script portable with little effort. I’ve tested the publish script on FreeBSD as well as Linux and it seems to work without any issues. For the most part, since I only wanted to clean up and organize the script and didn’t want to change its behaviour, I could just copy and paste most of what I already had in the script into functions with small tweaks here and there.

The refactored version of the script weighs in at 7070 bytes, 267 lines, and 183 source lines of code as of the time of writing. This is in comparison to the previous iteration of the script which weighed in at 4543 bytes, 181 lines, and 106 source lines of code. The new script is definitely larger, but also way more maintainable and portable.

As a consequence of this rewrite, I also noticed some undesirable behaviour: since publish calls compile, if auto-uploading was enabled in compile, the markdown files changed by publish would be uploaded twice. To solve this, and to make compile easier to use in general, I added argument parsing and a few command line options to the compile script. Now that script includes command line switches to print brief help text and toggle strict markdown compilation and auto uploading.

Another addition I made was to include the text of the <meta name=description> tag in my Mastodon status updates. Before I used to just post “New Blog Post:” with the title of the post and a URL, but now a quick summary of the post will also be included in the status updates which provides extra context and makes it easier for people to decide if they care to read the post or not.

You can view the updated version of the script in the repository for this website. It’s portable between operating systems but, unlike compile, it wasn’t really written for other people to use for their sites. Therefore, if you wish to adapt it for your own site, there are a few changes you’ll have to make and you should go through the entire file and make sure things like hard-coded paths and such are set for your environment.

This is my forty-second post for the #100DaysToOffload challenge. You can learn more about this challenge over at