Building Hugo with bob

Andrei Boar
benchkram
Published in
3 min readJul 8, 2022

You’ve probably heard about Hugo, the amazing open-source static site generator. But you probably haven’t heard about bob. Yet.

bob is still a new kid on the block, with the ambition to become your favorite build tool. Written in Go, it has many features: isolated and reproducible builds, dependencies management with nix, and its own terminal UI. Once you start working with bob you’ll notice how much of a weight is taken off your shoulders.

For the purpose of this article, I will focus on how to use bob to build Hugo from sources. You might want to do that in case you’ve decided to contribute to open source or just want to see how bob toolchain works.

Before we get started

Before we get started we need 3 things: go, git, and bob installed. You probably already have the first two, so just go ahead to bob install page to get it on your system.

Create your bob project

In our favorite shell we will create a new directory where we will clone Hugo's source code:

mkdir hugo-contrib
cd hugo-contrib
git clone git@github.com:gohugoio/hugo.git

Now we will create a bob.yaml file inside that directory to make it a bob project. We refer to bob.yaml as bobfile, similar to Dockerfile from Docker another tool that plays nice with bob. The bobfile will have the following contents:

Save the changes and run your first bob command:

bob build

You will get the following output:

After running this command you’ll notice the binary was created inside the ./build directory. You can run it and see if it works:

./build/hugo --help

You’ll also notice that the build operation took 460ms. Let’s try to run build again:

Now the whole build took 20ms because we didn’t change anything inside ./hugo. That’s the purpose of input in the bobfile:

input: ./hugo

bob will cache your build, so if nothing changes it will not build it again. The above statement says that if something changes inside ./hugo, it will build again.

Modify Hugo

Now it’s time to add a simple change in Hugo source. Go ahead and edit the main.go file inside hugo directory and add a simple fmt.Println statement at
the end of the main function:

Run bob build again and then run the binary:

bob build
./build/hugo — help

You should get your change reflected in the new output:

Next steps

You might think to yourself, so what? Why can’t I use go to build Hugo? Well, so far I’ve just introduced you to the simplest bob build command.
What if I told you that you don’t need manually install go or git on your system? You’ll have many projects you want to contribute to, maybe you don’t want to pollute your local system with different packages.

Or maybe you’re working on a project with multiple git repositories and you want a clear way of running them without having to memorize commands. bob will help you achieve all that with no effort from your side.

This is just the beginning. In my next series, I will show you how bob can manage your project dependencies and we can try to see if we can replace
mage, the build system used by Hugo, with bob and make a comparison.

For now, go have a look at bob docs and start adding it to your projects. Happy coding!

--

--