I won’t go into the details of creating a site with Hugo, the website covers that pretty well. I’ll merely be going over the setup of my update and deployment workflow. I found there were a lot of blog posts online, but few of them were able to help me 100%. Hopefully, this will also serve as a cheatsheet if I ever have to install another Hugo site in the future.
Hugo to Github Deployment
Everything is the same here as described in the Hugo docs, apart from the Git repository setup and the
Instead of creating a Git subtree for the
public directory, remove the
public directory (if it exists) and add it to a
.gitignore file. This avoids committing the generated files in two different branches.
deploy.sh script below adds any modified content files (e.g. pages, posts, etc.) to Git and automates the source deployment to your Github
master branch. Place this in the root directory of your Hugo site.
#!/bin/bash echo -e "\033[0;32mDeploying updates to GitHub...\033[0m" # Add changes to git. git add -A # Commit changes. msg="deploying updates `date`" if [ $# -eq 1 ] then msg="$1" fi git commit -m "$msg" # Push source and build repos. git push origin master
Add and commit these changes and push them to your Github repository.
Wercker Processing and Deployment
Now that Github deployment is automated, Wercker can be configured to watch for pushes to our repo. The Hugo documentation does a good job of explaining how to setup a Wercker application, so I won’t repeat it here. Each push to the Github
master branch will trigger Hugo to build the static files and deploy the generated files to the
Setup a Forestry.io site
Forestry.io provides a web-based front-end for adding or editing content on Jekyll and Hugo websites. Whilst some prefer to write content in a text editor and manage their site from the command line, having a visual editor keeps things simple and I can draft a blog post from anywhere I have internet access.
Signup with Forestry.io with your email address or Github account. I suggest linking your Github account, since you’ll need to provide access to your repository anyway. Once your account is created, follow the import wizard to add your Hugo repository from Github. It might take a while for Forestry.io to setup your site. Make a tea or coffee, catch up on some emails, Facebook, or Instagram and check back in a little bit.
Once your account is imported into Forestry.io, check if everything is working by making a test post:
- Write a post on Forestry.io and publish it.
- Check your Github repository for the latest commit from Forestry.io and note the commit hash.
- Check your Wercker dashboard for a new build job corresponding to the commit hash noted in step 2.
- Navigate to your URL and view your new post!