How to add a theme using modules (for beginners)

Thanks all for those informations. Since this post is now closed I hijack this thread to give some more hints.

After not succeeding to use modules even after reading those great post and the doc, even if I’m pretty comfortable with Hugo, I finally got some aha! moment when I realised that you need to understand somethings the Golang users know for a long time, but hidden for us poor mortals only using Hugo.

Do not hesitate to correct me if something is wrong or not really accurate. Here is the 2 simple things:

The path name module.

  • If you want to create/develop a module, you create your git folder module1-hugo as usual.
  • But the name module you give cannot be a local name (aka module1-hugo).
  • It has to be with a domain name as prefix (aka github.com/divinerites/module1-hugo)
  • So now you can initiate the Hugo module with the command : hugo mod init github.com/divinerites/module1-hugo, and reference it later in your path directive.

The version numbers

  • Unless you’ll give a (semantic) tag version number (aka v1.0.3) to your git commit, trying to use modules will fail with diverses error messages.

If you follow those 2 basic (for Go & Go modules users) recommandations, then using Hugo Modules is easy and so powerful (thanks Bep for this fantastic implementation).

May be just 2 other things, already in those great tutorials, but better say that again here:

  • A useful basic commands to update only one module from your internet repository : hugo mod get -u github.com/divinerites/module1-hugo
  • When you want to update/develop locally the beauty of modules is that you just add a replace directive for the module in your project go.mod, and bim bam boum, the local module folder is in use, with a fresh Hugo reload in millisecond. No need to do the merge/push/tag/update dance. Brilliant.

replace github.com/divinerites/module1-hugo => /Users/mycomputername/Documents/Git/module1-hugo

4 Likes