Are mounts incompatible with directory-based multilingual sites?

I have the standard directory structure:

content/
  en/
  es/

(With more than two languages.)

Then, in my languages entries I have the standard:

languages:
  en:
    contentDir: content/en
    # ...
  es:
    contentDir: content/es
    # ...

But now, I want to additionally use the Union fs to overlay more content:

content-private/
  en/
  es/

But adding the mounts breaks my templates:

module:
  mounts:
  - source: content
    target: content
  - source: content-private
    target: content

These seem like orthogonal concerns: here, contentDir is a higher level of abstraction than mounts. I.e., specifying mounts shouldn’t disable the contentDir in language configs.

At any rate, is there a way for this to work?

Hmm — maybe I can arrive at a solution by starting with the output of hugo config mounts? I learned about this command here: Hugo 0.56.3: A couple of Bug Fixes | Hugo Docs

$ hugo config mounts
{
   "path": "project",
   # ...
   "mounts": [
      {
         "source": "content/en",
         "target": "content",
         "lang": "en"
      },
      {
         "source": "content/es",
         "target": "content",
         "lang": "es"
      },
      # ...

Update, yep! I created a mounts entry that now works with my directory-based multilingual site. It’s very repetitive and verbose. In a perfect world, this could be one or two lines of configuration. But here it is, from my config file:

module:
  mounts:
    - source: content/en
      target: content
      lang: en
    - source: content/de
      target: content
      lang: de
    - source: content/es
      target: content
      lang: es
    - source: content/fi
      target: content
      lang: fi
    - source: content/fr
      target: content
      lang: fr
    - source: content/he
      target: content
      lang: he
    - source: content/hi
      target: content
      lang: hi
    - source: content/it
      target: content
      lang: it
    - source: content/ja
      target: content
      lang: ja
    - source: content/ko
      target: content
      lang: ko
    - source: content/nl
      target: content
      lang: nl
    - source: content/no
      target: content
      lang: 'no'
    - source: content/pl
      target: content
      lang: pl
    - source: content/pt
      target: content
      lang: pt
    - source: content/ru
      target: content
      lang: ru
    - source: content/sv
      target: content
      lang: sv
    - source: content/uk
      target: content
      lang: uk
    - source: content/vi
      target: content
      lang: vi
    - source: content/zh
      target: content
      lang: zh
    - source: content-private/en
      target: content
      lang: en
    - source: content-private/de
      target: content
      lang: de
    - source: content-private/es
      target: content
      lang: es
    - source: content-private/fi
      target: content
      lang: fi
    - source: content-private/fr
      target: content
      lang: fr
    - source: content-private/he
      target: content
      lang: he
    - source: content-private/hi
      target: content
      lang: hi
    - source: content-private/it
      target: content
      lang: it
    - source: content-private/ja
      target: content
      lang: ja
    - source: content-private/ko
      target: content
      lang: ko
    - source: content-private/nl
      target: content
      lang: nl
    - source: content-private/no
      target: content
      lang: 'no'
    - source: content-private/pl
      target: content
      lang: pl
    - source: content-private/pt
      target: content
      lang: pt
    - source: content-private/ru
      target: content
      lang: ru
    - source: content-private/sv
      target: content
      lang: sv
    - source: content-private/uk
      target: content
      lang: uk
    - source: content-private/vi
      target: content
      lang: vi
    - source: content-private/zh
      target: content
      lang: zh

contentDir defined on language work in combination with mounts. The side effect you see is (I guess) is not related to the content mounts.

The thing is (and this should be marked clearly in the documentation):

  • When you don’t set up any mounts, Hugo creates a default set (taking any contentDir setting into account)
  • When you set up one or more mount, Hugo will not create any default mounts (e.g. layouts), but will still take any contentDir setting into account.

We added mounts as a “new way to configure” general file mounts at some point, and added that logic to preserve backwards compability while allow for a fine greained mount config (some sites only need the layouts directory, so it would be wasteful to set up data, assets etc.).

2 Likes