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 gitcommand);
- Hugo;
- GitHub;
- A Hugo theme of your choice. I use Anatole;
- Notepad++, Markdown editor, Vim, whatever.
Steps:
- Make a cup of tea.
- 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.
- Clone this repo on your PC.
- 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.
- 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
- Add this from the root of the repo: .github/workflows/gh-pages.yml.
- Copy this into gh-pages.ymland 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
- Sip tea, or make another cup if it has run out.
- MAKE SURE YOUR NEW HUGO POST HAS DRAFT SET TO FALSE. cries in three hours loss
- Git add, commit, push.
- Sip tea while Github get the files and run the action.
- In the Github repo page, go to Settings > scroll down to GitHub Pages > expand the Branch drop down and select gh-pages > hit Save.
- 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.
