How to: Using a custom domain (apex domain and www subdomain) for a Hugo-generated page hosted on GitHub Pages.
What better first post than a meta post detailing the experience of getting my page running under my own domain in the first place. On the true developer-scale probably right below writing your own custom static site generator (in Rust or Kotlin, of course). If you’re too cheap for the all-inclusive Wordpress experience, too vain to just use the <username>.github.io domain, or too lazy to read the actual (very decent docs), this one’s for you!
Hint: The instructions assume you already have your domain registered and a Hugo page lying around on your disk somewhere. In my examples, I will describe the setup with the domains (www.) romanboehm.com and rmnbhm.github.io. If you want to follow along, exchange those with your own domain and your desired additional .github.io domain.
Those are the steps needed to make it work:
romanboehm.com. 1 IN A 185.199.111.153
romanboehm.com. 1 IN A 185.199.110.153
romanboehm.com. 1 IN A 185.199.109.153
romanboehm.com. 1 IN A 185.199.108.153
www.romanboehm.com. 1 IN CNAME rmnbhm.github.io.
git remote add origin [email protected]:rmnbhm/rmnbhm.github.io.git
# .github/workflows/gh-pages.yml
name: github pages
on:
push:
branches:
- main # Set a branch to deploy
pull_request:
jobs:
deploy:
runs-on: ubuntu-20.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
if: github.ref == 'refs/heads/main'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
romanboehm.com
git push origin main
That’s the whole thing. You should verify your site is available under the desired apex, www, and github.io (sub-) domains. Don’t forget to update your config.toml to make use of the new base URL if you have any settings referencing the URL there.