Any way to flexibly reuse certain configs alongside site-specific configs?

What is the best way, if any exists, for me to achieve the below directory structure / outcome, when:

  • I am only building my sites locally, not in GitHub CI or the like
  • I don’t want to use symlinks (not as explicit as a config setting)
  • I don’t want to rely on remote repository paths (for one thing, I don’t want to have to push every little tweak to see it take effect)
  • I don’t want anything duplicated in any caches for each site (I thought modules do this, but then modules don’t apply for config anyway, if I understand correctly?)
├── my_local_reusable_stuff_directory
│   ├── configuration
│   │   └── _default
│   │       ├── config.toml
│   │       ├── params.toml
├── my_site_A_directory
│   ├── config
│   │   └── _default
│   │       ├── config.toml
│   │       ├── params.toml
├── my_site_B_directory
│   ├── config
│   │   └── _default
│   │       ├── config.toml
│   │       ├── params.toml

Setting configDir seems to be an all or nothing sort of thing, if I understand correctly it doesn’t seem like I can have both a configDir in my site directory and my reusable stuff directory?

If I want to use a shared configs directory that uses the multiple files and environment-based directories structure, then my only option in my local sites directories is to use a single config file in the site root, and stuff everything else in it, including theme-specific params, menus, etc?

Is there anything equivalent to being able to define both a configDir and a configSharedDir?

Actually, they do.


Let’s say I have a directory in my user profile that contains shared configuration settings:

└── config/
    └── _default/
        ├── config.toml
        └── params.toml

And I have a project directory for one of my sites:

└── config/
    └── _default/
        ├── config.toml  <-- import "shared-hugo-stuff" here
        └── params.toml

Let’s import the “shared-hugo-stuff” directory as a module:

path = '/home/user/shared-hugo-stuff'


This setup merges the configuration from both locations, with project settings taking precedence.

You also have granular control over the merge behavior for each of the major configuration keys (markup, params, etc.). See the merge configuration documentation.

Although this may be unexpected behavior, I was able to merge some of the root level settings as well (e.g., title, copyright) by setting _merge in the root configuration to any value, including none.

_merge = 'none' # Not sure why this works.

But I was unable to merge other root level settings such as enableEmoji.

1 Like

Thanks, this seems to mostly work now that I am understanding it better.

One non-critical issue I run into, when I try to split content into both the shared directory and the project directory is with references in the content files breaking if I treat both content directories as modules (they don’t break otherwise).

I have an example content file from a theme, which I have placed in my primary content directory, which contains this reference to a content file I have placed in the shared content directory, and it contains a passage like this:

These can be included in your website through either the [icon partial]({{< ref "docs/partials#icon" >}}) or [icon shortcode]({{< ref "docs/shortcodes#icon" >}}).

This renders properly if I just use the following approach in my project-level _default/config.toml file for the primary / project content directory (while treating the shared content directory as a module):

contentDir = "../content_repo/content"

But if instead I try this alternate approach in my project-level _default/module.toml file …

  path = '../../../shared_stuff'

  path = '../../content_repo/content'

… then I get these errors when running hugo server:

Change of config file detected, rebuilding site.
2023-01-12 16:46:24.400 -0500
ERROR 2023/01/12 16:46:24 [en] REF_NOT_FOUND: Ref "samples/icons": "/path/to/shared/content/docs/": page not found
ERROR 2023/01/12 16:46:24 [en] REF_NOT_FOUND: Ref "samples/icons": "/path/to/shared/content/docs/shortcodes/": page not found

I wondered if it is possible to overcome this, but I don’t have to treat the primary / project content as a module if this error cannot be overcome.