Managing Hugo themes with modules for new those new to Hugo

@moonlighter

The quick start guide provides this example to create a site and then install a theme as a Git submodule:

hugo new site quickstart
cd quickstart
git init
git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke.git themes/ananke
echo "theme = 'ananke'" >> hugo.toml
hugo server

The equivalent, installing a theme as a Hugo module, is:

hugo new site quickstart
cd quickstart
hugo mod init github.com/jmooring/quickstart
echo "theme = ['github.com/theNewDynamic/gohugo-theme-ananke']" >> hugo.toml
hugo server

Line 3 (hugo mod init) is necessary because the project itself must be a module. The identifier (github.com/jmooring/quickstart) can be anything, even “foo”, as long as it doesn’t conflict with the identifiers of other modules in your project. If you plan to keep your project under source control, either privately or publicly, use the tld/user/repo syntax.

The commands above produce this site configuration file:

baseURL = 'https://example.org/'
languageCode = 'en-us'
title = 'My New Hugo Site'
theme = ['github.com/theNewDynamic/gohugo-theme-ananke']

Although specifying modules in the theme array (as shown above) works fine, you have more control if you explicitly import the theme as a module:

baseURL = 'https://example.org/'
languageCode = 'en-us'
title = 'My New Hugo Site'

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

To add another module, for example, a content module:

baseURL = 'https://example.org/'
languageCode = 'en-us'
title = 'My New Hugo Site'

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

[[module.imports]]
path = 'github.com/jmooring/hugo-content'

To update modules, run hugo mod get --help for details.