Skip to content.

Automatically set your github.io domain in GitHub Actions

Collaborative websites need to be forked, but if you set a hostname variable, such as baseURL in Hugo, the forked website will load resources from the original.. Not ideal.

The fix I applied to my GitHub Actions CI to work around this:

jobs:
  deploy:
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: bash
    steps:
      - name: Build 🔨
        run: |
          hugo --baseURL https://${GITHUB_REPOSITORY%%/*}.github.io/${GITHUB_REPOSITORY#*/}

This overrides the configured baseURL at build time with your GitHub account name as the subdomain and the repository as the directory.

I share this in hopes it saves you the time I lost figuring this out!

avatar
Joe Heaton

Joe’s technology-focused murmurings.
comments powered by Disqus

Settings!