Intoduction

  • GitHub Pages allow to host static content directly from repository on GitHub. More about GitHub Pages you can find in documentation

  • Hugo is a static website generetor written in Go. More about Hugo you can find in documentation

Preparation

To host Hugo webpage on GitHub Pages I prepared 3 repositories:

Here was my steps:

1. Create empty Hugo site in blog folder.

cd blog
hugo new site . --force

2. Add theme repository as submodule

GITHUB_PROFILE="pelicandev"
git submodule add https://github.com/$GITHUB_PROFILE/hugo-theme-m10c.git themes/m10c

I use submodule, because I can make changes in theme and have history of that in my repository.

3. Add theme reference

Open config.toml and add this line

theme = "m10c"

4. Run local site server

hugo server

Now site is empty and need some configuration.

5. Site configuration

Here is my config.toml file after configuration:

baseURL = "https://pelicandev.github.io/"
languageCode = "en-us"
title = "Bartosz Pelikan"
theme = "m10c"

[params]
  author = "Bartosz Pelikan"
  description = "Cloud Technology Enthusiast | .NET developer"
  avatar = "/images/img.jpg"

[[params.social]]
  name = "github"
  url = "https://github.com/bpelikan"

[[params.social]]
  name = "twitter"
  url = "https://twitter.com/bartoszpelikan"

[[params.social]]
  name = "linkedin"
  url = "https://www.linkedin.com/in/bartoszpelikan/"

[[params.social]]
  name = "mysite"
  url = "https://www.bartoszpelikan.pl/"

6. Add first post

Add file 2020-06-20-Hello-World.md to /content/posts/2020.

---
title: 'Hello World!'
date: '2020-06-20'
---

First post

7. Publish site

Now it’s time to publish site to GitHub Pages. GitHub doesn’t support Hugo site generator, just Jekyll, but fortunately it’s possible to achieve this by sending static files.

hugo

This command will generate static files in /publish folder.

But before run above command let’s create in /publish folder submodule that will be GitHub repository hosting our site.

YOUR_GITHUB_PROFILE="pelicandev"
YOUR_GITHUB_REPO="pelicandev.github.io"
git submodule add https://github.com/$YOUR_GITHUB_PROFILE/$YOUR_GITHUB_REPO.git public

I created script publish.sh that will help me to publish site:

find public -type f -not -name 'CNAME' -not -name 'README.md' -not -name '.git' -delete
hugo
cd public
git status
git add .
git commit -m "Publish site $(date +"%Y-%m-%d %H:%M:%S")"
git push origin master

All what I need to do now is run sript:

sh publish.sh