Coding my site, why I moved away from Publii!
Introduction
When I moved from Digital Ocean to Strato I also moved into a Static Site solution with Publii. The application had benefits at the time. A little over a year ago I had some troubles with the default free template, with a update of that template the site broke. At the time no real time left to investigate properly in the why and how to solve. So I went for the “easy” solution in purchasing another template. Too busy to spend my downtime on my site. Priorities… After 6 months I realized that the use of the template was with a small caveat, namely the updates of the template were only possible inside a window of 6 months. Again no time to move in a different direction, got myself a “update” for another 6 months. These 6 months are almost up. And now I do have some time and I am willing to see what else is out there. After some investigation online I made the decision to do a deep dive into using Hugo. What I saw I liked, a lot! Being able to code my site, have it under VCS, and written in Go. Definitely a winner!
Finding the right template
To be realistic; I am not a frontend (websites) developer. But I am quite capable in hacking my way around in a number of languages and frameworks. Another template it is. Setting up a Hugo environment is really easy. The documentation is also pretty good. For me the site needs to be simple, clean and serving a simple purpose. Easy to add blog posts and a couple of “fixed” pages. I am not looking for all kinds of fancy stuff. A minimalist site. But also one I can easily change.
After a number of trying out some templates to see which ones fit the requirements the most, I kept on going back to the current template: m10c
I have made some small changes and quite happy with the outcome.
IDE
And what editor to use? Since at Pro we migrated to using Visual Studio Code in the summer of 2021, the IDE was thus VS Code. However on my personal iMac, the installation was outdated. Set the IDE up again, with the latest Go SDK and a matter of setting up the correct PATH and we are off to the races. Adding some extensions and ready to go.
Migration
How to migrate the data from Publii into Hugo Project? For the migration it is simple answer, there is no migration. Publii does not provide an exporter. Which is another reason to move away. And with the pages written in markdown when using Hugo, migration into another static site generator should not be that complicated.
Just a matter of re-creating the pages in the IDE. And because I only had some 21 posts to worry about, just doing it seems, and has been proven, faster. Could there be a way to convert the “html” from within Publii to markdown. Yes, found this clipboard2markdown. Just matter of ⌘-C in Publii and ⌘-V in the site. Presto; instant markdown to again copy & paste. Most time consuming was finding the assets of the posts and adding them into the workspace.
Template changes
Now I had the site working, the pages are in, the site runs locally and still some changes to be made in the layout. Thanks to the inheritance nature of Hugo, not that difficult:
- Added the copyright label
- Changed the primary color to match the green in my logo
- Created a new version of my logo
- Added the description to the list view.
Deployment
Since I use Strato as the hosting party I am “limited” to deploying using the CLI. Not really limited, in my case I even prefer it.
With Publii I already was using the SFTP option to upload the site into the web space. This should not pose a problem, wrong. The CLI solution documented in Hugo is using rsync.
Default the access to the web space is using a username and a password. Thanks to former colleague of mine, Armin, I knew that there is a way to store passwords in Keychain Access application and retrieve the password in the terminal. The storing and retrieving of the password worked like a charm, sadly rsync simple refuses to use the password. I tried to export RSYNC_PASSWORD
, the storing of the password in a file (yes, I know horrible solution… ;-) ) All kind of changes to the command, no luck.
While reading the documentation on Strato, I noticed the following note:
Tip: Met het programma PuTTYgen heeft u de mogelijkheid een speciale "sleutel" voor uw domein te genereren, zodat u bij het inloggen via SSH of SFTP niet steeds uw toegangsgegevens hoeft in te voeren.
Dit bestand wordt dan opgeslagen in een speciale map in uw webruimte.
To me this in layman-terms to tell the system should be able to use SSH Key-Based authentication, interesting!
With no or limited documentation, let’s see if I can create a SSH session. And yes I did.
So just a matter of creating a key-pair to use, add a config in my SSH config file and create the .ssh/authorized_hosts
file with right permissions, you would think. Nope, still that bloody password prompt.
When I open een SSH session I noticed that there is a warning about some key client_global_hostkeys_private_confirm: server gave bad signature for ED25519 key 2: incorrect signature
Could it simply be, that the RSA
key is not supported. So a matter of simply creating another key-pair, this time in the ED25519
format; >ssh-keygen -t ed25519
. Try again, worked instantly!! Great solution to the problem.
Now the script is fairly easy:
#!/bin/sh
USER=<username>
HOST=<host>
DIR=<path-to-folder-on-server>
# Removing all data in public folder
rm -Rf public/*
# Build Site
hugo
# Syncing the site
rsync -avz --delete public/ --rsh=ssh ${USER}@${HOST}:${DIR}
exit 0
This works, very nice. From within VS Code simply start the script and deployment done in seconds.
Conclusion
This blogging workflow is way better suited for me then Publii.Well, at this moment. Whop knows what I will do in two years time? Besides, it is nice manageable way to get back into building stuff in code.