This Blog

I don’t know about you, but I have let so many little achievements of my past laid to waste, because I forgot how to reproduce them. How did I make this game? How did I draw that? How did I make this blog? How did I make the best cookies I’ve ever had in my life? I can’t remember, and when I try again, it burns. Or it’s too sweet. Or too crumbly. Too doughy. Too imperfect. Too far from how I remembered it.

I’m kicking off this blog with how I brought this thing up and running.

Ingredients:

  • Command line with Git (Git Bash, plain Bash, Windows cmd, whatever that can run git command);
  • Hugo;
  • GitHub;
  • A Hugo theme of your choice. I use Anatole;
  • Notepad++, Markdown editor, Vim, whatever.

Steps:

  1. Make a cup of tea.
  2. Start a new repo on Github with the project name “[your-user-name].github.io”. This project name pattern will be automagically recognised by Github as a Github Pages project.
  3. Clone this repo on your PC.
  4. Make a new Hugo site using https://gohugo.io/getting-started/quick-start/ - No need to build the site but you can do it anyway to test the site locally.
  5. Add .gitignore with the Hugo template below. Thank toptal.
# Created by https://www.toptal.com/developers/gitignore/api/hugo
# Edit at https://www.toptal.com/developers/gitignore?templates=hugo

### Hugo ###
# Generated files by hugo
/public/
/resources/_gen/
hugo_stats.json

# Executable may be added to repository
hugo.exe
hugo.darwin
hugo.linux

# End of https://www.toptal.com/developers/gitignore/api/hugo
  1. Add this from the root of the repo: .github/workflows/gh-pages.yml.
  2. Copy this into gh-pages.yml and thank peaceiris.
name: github pages

on:
  push:
    branches:
      - main  # Set a branch to deploy

jobs:
  deploy:
    runs-on: ubuntu-18.04
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true  # Fetch Hugo themes (true OR recursive)
          fetch-depth: 0    # Fetch all history for .GitInfo and .Lastmod

      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v2
        with:
          hugo-version: 'latest'
          # extended: true

      - name: Build
        run: hugo --minify

      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./public
  1. Sip tea, or make another cup if it has run out.
  2. MAKE SURE YOUR NEW HUGO POST HAS DRAFT SET TO FALSE. cries in three hours loss
  3. Git add, commit, push.
  4. Sip tea while Github get the files and run the action.
  5. In the Github repo page, go to Settings > scroll down to GitHub Pages > expand the Branch drop down and select gh-pages > hit Save.
  6. Hard refresh everything, rerun the deploy action if you have to. It should work now. If not, get a glass of water and start figuring it out for the next 3 hours. Or take a nap - that worked for me.

Was it convuluted? Yes.

Did it take longer than other one-click solutions out there? Yes.

Is it guaranteed free and stable? You bet it is.

Was it fun? Eh depends. Watching it work in the end sure is though.