How to manage common config in Hugo using modules

We have multiple Hugo sites that all use a shared theme, which we’ve created as a module. Our goal is to centralize and manage all common configuration values within this theme module, so that individual sites don’t need to duplicate them.

We are referring: Merge configuration settings

We want common configuration (such as services.googleAnalytics) to live in the theme module and be automatically merged into each site’s config.

Common theme module (mymodule/)

mymodule/
└── config/
    └── _default/
        └── hugo.yaml

Contents of hugo.yaml in the module:

services:
  googleAnalytics:
    ID: G-SSSSSSSSS

Consuming site (mysite1/)

mysite1/
└── config/
    └── _default/
        └── hugo.yaml

Contents of hugo.yaml in the site:

_merge: deep

module:
  imports:
    - path: mymodule

services:
  _merge: deep

markup:
  _merge: deep

The issue

When we run: hugo config

the services.googleAnalytics.ID value from the module does not appear in the merged configuration.

We’d appreciate any clarification or guidance. Thanks!

I am unable to reproduce the problem. Try it:

git clone --single-branch -b hugo-forum-topic-54485 https://github.com/jmooring/hugo-testing hugo-forum-topic-54485
cd hugo-forum-topic-54485
hugo server

Perhaps there’s something different about the test site above.

The above should work just fine, but testing this myself now I noticed a odd bug that prevents it from being simpler:

E.g. if you want to do a deep merge of “everything”, adding the _merge=deep to root should be enough.

1 Like

Thanks, this worked perfectly for me!

I had to upgrade both Go and Hugo to their latest versions to get things running.

After the upgrade, my project is working fine too — though I’m not entirely sure if the upgrade itself was the key (I was using Hugo: 0.140, Go: 1.22).

Really appreciate your help!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.