Setup a Blog With Github Pages and Hugo

Always be yourself. Except if you can be Batman, then be Batman!

GitHub pages are super powerful and very easy to use for creating markdown based static websites.

In this post I will walk through how I made this very page.

My setup will be two GitHub repositories, one for the source of the page ( and the other where the html artifacts are deployed (

Here I would like to note that it is possible to use a single repository with two branches, one for holding the the source and the other where the website is deployed. I just personally find the two repository setup more elegant without any particular reason.


Account on GitHub

Git client installed

sudo zypper install git-core

hugo application installed

sudo zypper install hugo

Create and configure the hugo page and source repository

To start I have created the draft page source with hugo and pulled in the beautifulhugo theme as submodule.

hugo new site blog-source
cd blog-source
git init
git submodule add themes/beautifulhugo

At that point I used the instructions ( from Chris and even used his config.tml ( as template to create mine.

It is really easy to test drive locally the website by running the hugo server

hugo server

and open http://localhost:1313/ in the browser. I simple opened an other terminal and adjusted, extended the source tree and refreshed the page in the browswer. As long the hugo server is running it will watch the source tree.

After I was happy with the initial state of the website I have pushed the code to the source repository

branch -M main
git remote add origin
git add .
git commit -m "Initial commit" -a
git push -u origin main

Create and configure the GitHub page

Created a vanilla GitHub repository without any content

As I am going to automatically deploy the website from one repository to the other repository of the GitHub page I need to setup secure authentication

First I created a private/public key pair

$ ssh-keygen -t rsa -b 4096 -C "$(GIT USER EMAIL)" -f master -N ""

It will create the master/ key pair.

I have added the private key as a secret to the hugo source repository

In my case here

The place on GitHub is the Repository -> Settings -> Secrets -> Add new secrets and the name the secret I set ACTIONS\DEPLOY\KEY and pasted the contents of master file in the value.

Then added the public key as deployment key in the GitHub pages repository

In my case it is here

The place on GitHub is the Repository  -> Settings -> Deploy Key -> Add new deploy key 

I have set the “Public Key for the site deploy” as title and pasted the contents ofmaster.pubfile in the value.

From that point there is nothing to do with that repository. I can browse the html code of the website and if needed I can push there changes. But that would not make much sense as I use GitHub actions to automatically deploy the website when a new version is pushed to the source repository.

I went to the Actions section in the source repository here and created a new workflow.

The action will be stored in a yaml file under the source tree .github/workflows/ folder:

I paste here the action yaml file:

name: hugo publish

    - main

    runs-on: ubuntu-18.04
    - uses: actions/checkout@v1
        submodules: true

    - name: Setup Hugo
      uses: peaceiris/actions-hugo@v2
        hugo-version: '0.59.1'

    - name: Build
      run: hugo --minify

    - name: Deploy
      uses: peaceiris/actions-gh-pages@v2
        EXTERNAL_REPOSITORY: bzoltan1/
        PUBLISH_BRANCH: master
        PUBLISH_DIR: ./public
        emptyCommits: false
        commitMessage: ${{ github.event.head_commit.message }}

Note few important details here. 

As I am using the beautifulhugo theme as submodule, it is necessary to tell the action that it needs to update that submmodule with the “submodules: true”. Aslo remember to hook on the action  to the same branch where you push the source. In my case it is the main branch. The of course I needed to set the deployment environment properly. So the ACTIONS_DEPLOY_KEY, EXTERNAL_REPOSITORY and PUBLISH_BRANCH should be correct.

Workflow to create new posts

There are several good ways to create new content. I prefer to use the native hugo way in command line

$ hugo new posts/\[YYYY-MM-DD\]-\[TITLE\].md

Then I  simple edited the created markdown file with vi and fixed the header to have nice tags and changed the “draft:true” to “type: post”

title: "Setup a Blog With Github Pages and Hugo"  
date: 2021-04-05T19:36:57+03:00  
tags: ["hugo", "github", "workflow", "pages","website","opensuse"]  
type: post  

After I have edited the markdown file, all I needed to to do is committing and pushing the code to the source repository and let the GitHub CI do its job. 

$ git add post/
$ git commit -m "New blog post" post/
$ git push

What’s next?