Using Hugo with Github Pages: Part 2
The previous post featured on just getting a website up and running in hugo. This post focusses on customizing the website, to your liking and publishing it on github. There are three ways of accomplishing this in the documentation -
Make a docs folder in your website root, change the
publishDir
option in your config to docs. Then create an empty git repo not named as per.github.io. It can be named anything else. Then upload that to github, and in repository settings choose to publish the website from docs
folder. The issue is that this approach is for project pages, not the best suited for a personal website.The alternative given is to go with the gh-pages approach, mentioned in hugo docs. However, even this approach is only for project pages. Your website ends up getting named as
username.github.io/mywebsite/
which is not very encouraging. You ideally want your website to be called just username.github.io.You will get a username.github.io url for your homepage if you use
publishDir = "."
in yourconfig.taml
. However, then your project root folder will get cluttered with a barrage of files and folders from the generated website. Its never a good idea.
The solution to above issues is actually to create two git repos. Github only publishes the repository <username>.github.io
on a website by the same name.
Create a new repository on github with the name
echo "public">>.gitignore
git init
git remote set origin "<url to your repo>"
git status
git add .
git commit -m "First commit"
git push
This should push your website into github. However, notice that we didn’t push the ‘public’ folder. This is because we will create a new git repository inside public, and set its upstream to
cd public
git init
git remote set origin <url to your username.github.io repo>
git add .
git commit -m "Initial commit for published website"
git push
And done! Now if you navigate to settings
page of your
- A repository named username.github.io that tracks the content
public
folder of our repository.
In the next post, I’ll be talking about basics of working with hugo, and how to modify the supplied theme elements to get desired look & feel and behavior of the website.