Skip to content

Instantly share code, notes, and snippets.

@tjstebbing
Last active May 8, 2023 11:54
Show Gist options
  • Save tjstebbing/6788865f17c5ce06ff953f524264da54 to your computer and use it in GitHub Desktop.
Save tjstebbing/6788865f17c5ce06ff953f524264da54 to your computer and use it in GitHub Desktop.
First test blogpost using gist as the source and hugo to publish

+++ categories = ['hax'] date = '2023-05-08' description = 'Hugo + gist + sh' slug = 'gist-powered-blog' title = 'Gist + Hugo + Bash Blog' +++

Over the past few weeks I've been noodling around setting up this website in my spare time. I have a lot to say personally about the work that I'm doing that isn't really appropriate from my employers official blog, and I wanted somewhere I could drop my own thoughts as an individual.

It's a small thing but I believe that net neutrality and decentralisation are critical for maintaining free speech, and as such self-hosting my content is important, even if I promote via socials. This website is currently running on a Raspberry Pi on my desk, and you got here by dynamic DNS lookup and a port-forward from my home router. Eventually I plan on migrating this to solar + battery + starlink running inside my 4x4, but one step at a time.

For me Hugo has been my goto static hosting system. I find it's simple and effective and I'm able to get something together quickly. This time around I needed a remote-editing system that will let me publish content even if I don't have my laptop handy, and so I've simply dropped a bash script into crontab that searches my Github gists for 'blogpost.md' and pulls them down with curl.

#!/bin/bash

gist_list=$(curl -s "https://api.github.com/users/tjstebbing/gists")

# Loop through each gist in the list
for gist in $(echo "${gist_list}" | jq -r '.[] | @base64'); do
  # Decode the gist JSON and get the URL of the raw 'blogpost.md' file
  gist_json=$(echo "${gist}" | base64 --decode | jq -r '.')
  blogpost_url=$(echo "${gist_json}" | jq -r '.files."blogpost.md".raw_url')

  # If the 'blogpost.md' file exists, download it
  if [[ -n "${blogpost_url}" ]]; then
    curl -s "${blogpost_url}" -o "$(echo "${gist_json}" | jq -r '.id').md"
  fi
done

Once this is done hugo rebuilds and the results are served up via NGINX running on the Pi. Gist is a nice choice because folk who want to can comment via github.. eventually I could write some client-side JS to pull down the comments and display them under the posts.

I like simple things, lets see how this goes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment