Moved to Hugo

Wow, that was weird.

So, the last two days you may have seen this site go from weird points of looking like my original Ghost CMS blog, to this more simplistic look. The reason why is because I took a look at what Ghost had been costing me to host on a digital ocean droplet for the last few weeks ($20/month) and there was money to be saved.

So I manually replicated each of my previous posts over to markdown format, and started looking into static site generators. Among the possible candidates (at least to me) were Jekyll and Hugo, I ended up going with Hugo simply because it felt newer and while not exactly as widely supported had been picking up quick steam in the static site generation game. Plus, I already utilise jekyll for my GoRoMa project and wanted to branch out into something different.

Anyhow, biggest hurdles with this move:

  • Learning how Hugo works.
  • How to set it up.
  • Storing all my content for this blog on github (in a private repo).
  • The limitations of cloudflares pages service (I at one point thought hugo extended wasn’t supported on their V2 machines, wrong! Hugo Extended is the default flavour being used)
  • Creating a github workflow for wiping the cloudflare cache.
    • Evidently should you not wipe the cache, even despite a new deployment to their pages service it’ll display old content until the TTL is reached. So a github workflow to remove all the older cached objects was desirable in the event I send out a post I want to quickly claw back or a post that I think is majorly beneficial in the moment.

For anyone wondering, here’s my code for the github workflow action.

name: New Push to Main

on:
  push:
    branches:
      main

jobs:
  Purge-Cloudflare-Cache:
    runs-on: ubuntu-latest
    steps:
      - name: Send cURL request to Cloudflare API
        run: |
            curl -X POST "https://api.cloudflare.com/client/v4/zones/${{ secrets.CF_ZONEID }}/purge_cache" \
            -H "Authorization: Bearer ${{ secrets.CF_TOKEN }}" \
            -H "Content-Type: application/json" \
            --data '{"purge_everything":true}'            

It takes on average about 10 to 15 seconds to run each time via githubs runners. Which is good since it won’t blast through private minutes.

github runner times

It uses two repo secrets, one for a ZONE_ID (which you can get from the actual website overview in cloudflare), and another I called the CF_TOKEN which is just the bearer token/secret for authing with your CF instance.

And for additional context, this is how my API token was configured for minimal risk:

cloudflare token configuration

Cloudflare pages is also pretty good, building this entire site and having it deployed on CF from the point of a new commit/push to the blog repo on github takes on average 10 seconds, with a majority of that time spent sending the actual assets to cloudflares infrastructure.

I’m getting 98+ in every google pagespeed insight metric and I no longer have to pay for hosting. Additionally I’ve blocked AI from being able to scrape the page for their learning, chatGPT/bard users are also no longer able to get that bot to inspect my site, I just feel I should be paid for my writing efforts /shrug.

Fun little aside, I created a humans.txt file at the root of this domain which is also created on each build of the site, and that itself has the time the site was built as well as a few other easter eggs haha. I always try to sneak a little something into my work. As I write this it looks like:

/* SITE */

Last built: 2024-02-05 14:58:51
Standards: HTML, CSS, JavaScript
Hosted on: Cloudflare Pages (pages.cloudflare.com)
Software: HUGO, Visual Studio Code, Github

All in all, good move. Time to push this post out and watch it compile :)