Modules
Updated on
Last site update: 8 May 2024
To add something to a theme using Hugo modules you need to:
- Make your site a module (this process just adds a couple of files:
go.mod
andgo.sum
) usinghugo mod init
see gendoc. - Add some code, like that below, to your config file.
Next you can either:
- Start Hugo server and see the content pulled from elsewhere
- Build the site using
hugo
and pull the content into the build site. - Upload the site
1[module]
2
3[[module.imports]]
4 path = "github.com/craftsmandigital/markdown-content-repo"
5 disabled = false
6
7[[module.imports.mounts]]
8 source = "testing-hugo-modules"
9 target = "content/new-stuff"
Update
1hugo mod get -u github.com/twbs/icons
Fail
Trying to get some images from Mega.nz
1$ hugo -D
2hugo: collected modules in 960 ms
3Error: module "https://mega.nz/folder/7JYihLTB#FclpuFHngNKPNyXnRul2_Q" not found; either add
4it as a Hugo Module or store it in "T:\\HTML-extras\\TRYOUTS\\hugo-test-1\\themes".: module does not exist
Comment from Bep
A related hint from me (which should get a more prominent place in the docs):
Hugo uses a
/tmp dir
for the cache if cace dir is not set (in config.toml or environment)
Go downloads the modules and write protects all directories
On MacOS I have experienced some occasional issues which I guess relates to MacOS trying to clean out these directories, but only partly succeeds.
SettingHUGO_CACHEDIR
os env variable to something outside/tmp
is the solution to the above. It’s also in general a good thing.
Links
- The New Dynamic
- Hugo Modules for Dummies on the Hugo forums.
- Hugo docs on modules
- Hugo mod help page