Hugo Modules for Themes

Instead of git submodules

The tutorial for Hugo tells you how to install themes in step 3. This is great because you probably want to pick one of the hundreds of beautiful 3rd party themes to get hugo to do what you want it to do.

git init
git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke.git themes/ananke
echo theme = \"ananke\" >> config.toml

This has some problems. Mainly that I don’t want to learn how to work with git submodules 😄 but also.. I don’t understand git submodules 🙄. But I don’t have to! Apparently Hugo has created the concept of Hugo modules. They are basically Go modules.

# How do you use them?

Firstly you have to make your site a Go module, hugo can help you with this.

hugo mod init <any-name-you-want>

Then you add your themes/modules to a hugo module config.

[[imports]]
    path = "github.com/theNewDynamic/gohugo-theme-ananke"

Notice that the path does not include https:// or .git. Don’t add them, it won’t work.

Lastly delete the git submodules in /themes, git submodule config (.gitsubmodules file) and the theme = "ananke" from config.toml. Done!

As a little extra here are some nice hugo modules I’ve recently started using, which you can try to add as a hu(go) module!

  1. social media metadata
  2. colourful notices to use in your pages to highlight warnings etc
hugo 

See also