Did you know Hugo has this feature called Modules? Apparently built on the same concepts of Go Modules, which shouldn’t be a surprise.
So having used all my hugo themes so far as Git Submodules, I wanted to switch over to this method.
Hugo modules are considered to be the building blocks of Hugo. It is the Hugo way of modularising your static website. Apparently you can create a theme as a module and content as another module and use them together in a third module to serve as your static website. I didn’t go that far just yet.
My primary objective was the need for a slightly easier way to manage my themes. This is a very subjective opinion. I felt like I always had to remember how to fetch the latest version of git submodules. The module approach makes it significantly easier with just a hugo mod get
. I might be oversimplifying here but it is definitely easier to remember that than how to update your git submodules.
How to use Hugo Modules for managing your themes?
Jon Arne Viskås has written about this in his post Hugo Modules. He based this on a post by chreliot in Hugo’s discourse.
I saw that post in discourse and blindly tried it without thinking much and ended up with an error, similar to the one in this post that got me searching for all sorts of ways to resolve it.
What was the cause of the problem?
Apparently when you use a theme as a module, you don’t need to set the theme
parameter in your config.yaml
.
It was one or the other!
Bep actually states this in a response to chreliot’s post.
However, I missed that for an entire 24 hours. Don’t worry, I wasn’t in front of my laptop trying to debug hugo modules the whole day. I just got back to it after a night. Although technically it is the same, when I introduced this hugo module and deleted my themes
directory where I had the themes I had downloaded using the git submodules method, Hugo failed to build my site with the module not found error. This left me so confused.
The simple fix for me was to remove the theme
configuration from the config.yml
.
One can use multiple modules in a project so my config.yml
, now imports the theme like:
module:
imports:
- path: "github.com/adityatelange/hugo-PaperMod"
The real reason
I was looking for user interface elements that puts warnings, information, notes, errors etc on my blog and stumbled upon hugo-notice. While going through how I could use it in my blog, I realised that the easiest way was to import it as a module!
This made me realise that I hadn’t started using modules yet, despite using Hugo for my blog for 3 years now! Not that I put a post out every day, but these subtle visual cues make for a better reading experience.
So that’s my next step - introduce hugo-notice in my blog and also use it in a post that I am about to finish.