Static Blogging with Hugo, GitHub Pages (Travis CI, Cloudflare)
· 2 min read
Github
-
Create two repositories on Github:
- Content source repository (the result of
hugo new site): https://github.com/fahrinh/my-site - Main web pages repository (the result of running Hugo): https://github.com/fahrinh/fahrinh.github.io
- Content source repository (the result of
-
Create a Personal Access Token at https://github.com/settings/tokens with the repo scope. Copy the token to your clipboard.
-
Make sure there is a
CNAMEfile containing the custom domain in the https://github.com/fahrinh/my-site repository.
Travis CI
- Create a
.travis.ymlconfiguration file in the https://github.com/fahrinh/my-site/ repository with this content:
language: go
go:
- master # This uses automatically the latest version of go
install:
- pip install --user pygments
- go get github.com/spf13/hugo # This provides the latest version of Hugo to Travis CI
script:
- hugo version
- hugo --theme=hugo-pacman-theme # This commands builds your website on travis
- cp CNAME public
- ls public
deploy:
local_dir: public # Default static site output dir for Hugo
repo: fahrinh/fahrinh.github.io # This is the slug of the repo you want to deploy your site to
target_branch: master # GitHub pages branch to deploy to (in other cases it can be gh-pages)
provider: pages
skip_cleanup: true
github_token: $GITHUB_TOKEN # This is the authentication which you will setup in the next step in travis-ci dashboard
name: "Fahri Nurul Hidayat"
on:
branch: master
- Create a
GITHUB_TOKENEnvironment Variable at https://travis-ci.org/fahrinh/my-site/settings with the Personal Access Token you created earlier.
Cloudflare
- Set up DNS with the root domain
nurul.id - Replace your hosting provider's nameservers with Cloudflare's nameservers
- Under Crypto, enable Always use HTTPS and Automatic HTTPS Rewrites
Source: https://martinkaptein.github.io/blog/hugo-with-travis-ci-on-gh-pages/
