Tags: PublishingOnline Linux notes Hugo technicalNotes CodeJournal
My earlier website was based off Hugo. The complete source is available as a Git repo at shrysr/sr-hugo. Currently, my only actions are to make changes to an Org source file and export the same via ox-hugo. There are several branches in that repo which contain my experiments in adopting different themes.
Even the export of the subtree or the file via ox-hugo can be automated via the TODO/DONE states. I currently prefer not to do so, but intent to gravitate to that soon.
The website is hosted on a Linode VPS running a Debian OS. Since I started off with a self-hosted Wordpress setup, I have a LAMP stack set up.
While a LAMP stack is not necessary for running a static hugo website, it is still useful for other purposes like hosting multiple wikis or blogs and websites or apps on the same server. Nginx is an alternative to the 'A' (in LAMP) for Apache. In case of using Nginx, the general acronym is replaced by an E (as in LEMP). It is also not really necessary to have the 'P' (PHP) or M (MySQL?) setup if one is not using Wordpress (or other applications that need these) for a Hugo site. Both Linode and Digital Ocean have nice tutorials that take you through the setup step by step.
The idea here is that the website development (including generating content) and testing the website will take place locally and the VPS is only meant to serve the website. i.e direct development of the website on the server will be avoided unless necessary. In a way this mimics production environments, though there are better technical ways to do so. For example, using git branches, or adding additional steps in between like a fetch and a compare and a final test. This is being eschewed at the moment, since I will test the website locally before deploying changes.
hugo serve
command in the root of the hugo site directory.-d
flag was used alone, it means the website is essentially re-constructed from scratch and pushed each time.A cron job is usually created using crontab -e
. Note that the same approach can be used to create/edit crontabs for other user
using the sudo -u user crontab -e
. Also note that apparently variables like $HOME
do get expanded by cron jobs since these are probably globally defined.
*/10 * * * * sh /home/username/src/hugo-pull-deploy.sh
#!/usr/bin/env zsh # Script to git pull hugo site repo and deploy. This script is called by # a cron job. Replace username with your username. Note that I have # compiled hugo from the source to obtain a specific version which was # necessary for my theme and also to maintain parity with my local hugo # version. This can be added to my path if desired. Since only limited # commands are run using hugo at the moment, I have not yet done so. # Setup the trap. This will ensure the background process is killed when # the script is finished. trap "kill 0" EXIT # Hugo project root directory. It's easier to work from here. cd /home/username/hugo-sr # Start the hugo watch process in the background to monitor the hugo # root directory and send updates to the destination, if any. /home/username/go/bin/hugo -w -d /var/www/html/website.name/public_html/ & # Pull in the latest from the remote git pull # Sleep for good measure though hugo generates the site in seconds sleep 2m
"A picture of how my my current Emacs setup looks like. The window on the left is the Org document where I type content. The top right window is a file explorer in case I want to inspect the markdown export. The bottom right window is the on-going Hugo server. Alternatively, I can eschew the file explorer windows for a nice Treemacs workspace (which is usually how I roll).")
I use the excellent ox-hugo package to maintain my entire blog in a single Org file. Any screenshots or pictures are simply added via drag and drop (org-web-tools and org-download) and ox-hugo takes care of exporting the pictures the correct directory. I doubt it can get too much easier than it is right now. The only thing that would make it easier if I just commit an Org source file, and have an automated process to check whether the site builds as expected or not.
I've tested the above and it works satisfactorily. All I have to do at the moment is write my post in Org mode and export via ox-hugo. The deployment is automated, and is reasonably efficient, though there is always scope to make it better.