on
Deploying a Hugo Blog with Travis CI
I have enjoyed using Hugo to build my blog, but I have not been happy with the deploy process to GitHub Pages. GitHub user pages always deploy the master branch of the project and also does not directly support Hugo. This means you need at least two branches to make this work, one for the source and one for the release. Up to this point, I was using the pattern suggested by the Hugo team for this. This involves having one repository for the source of my blog, and then pushing the built files to a subproject that pointed to the repository that is deployed to GitHub Pages. I didn’t love that this required having two repositories, and the process to release was automated with a script but wasn’t as clean as I would have liked. I had a chance, recently, to use the GitHub Pages deploy with Travis CI, and I thought it could work well with Hugo too.
I had two goals with the transition:
- Use a single repository for source and release
- Be able to automate deployment such that the blog could be released each night.
To accomplish this I followed these steps.
- Create a new, empty repository
- Create a
source
branch, where the raw blog source will live - Make the
source
branch protected on GitHub, just to be safe - Add the
public
directory to my .gitignore - Add the following
.travis.yml
to my project
|
|
With these changes, each time I push new code to the source
branch, Travis will build the site and deploy it to
GitHub Pages. Along with that, I can configure Travis CI to build my source branch each evening, allowing me to date
my posts with a target date, and have them release automatically for me.