Content mount problem for single-language "multilingual" site

Hi,

For open-telemetry/opentelemetry.io, I’m trying to bring in content from a separate repo/directory using an entry like this:

module:
  mounts:
    - source: some_path_for_extra_content
      target: content/extras

The site already has source/target entries for static, but as soon as I add the following (and nothing else), all/most of the site content is “moved” / gets generated under /en rather than the current site-default of /:

- source: content
  target: content

Whether I add lang: en or not has no effect. Any ideas how to avoid this?

In case this helps, here are the language config settings for the site:

contentDir: content/en
defaultContentLanguage: en
defaultContentLanguageInSubdir: false
enableMissingTranslationPlaceholders: true
languages:
  en:
    title: OpenTelemetry
    description: The OpenTelemetry Project Site
    languageName: English
    weight: 1

I am unable to build this site due to a number of errors. Can you boil this down to a small, reproducible example?

Hi Joe, thanks for looking into this. Sure I could create a smaller example, but might you be willing to try a GitPod.io setup by visiting: https://gitpod.io/#https://github.com/open-telemetry/opentelemetry.io. It should work out-of-the-box. Then run (the first two steps might be optional):

$ nvm install --lts
$ npm install
$ npm run build

Details are in CONTRIBUTING.md.

If not, let me know and I’ll try to create a smaller repro.

Speaking only for myself, I am less inclined to look at a problem when I have to jump through hoops to reproduce it. Additionally, when creating a minimal reproducible example, the underlying problem will often reveal itself.

Here goes! I don’t have your super test gen script so I started from the closest existing test I could find in your test repo:

git clone --single-branch -b hugo-forum-topic-37165 https://github.com/jmooring/hugo-testing hugo-forum-topic-37165
cd hugo-forum-topic-37165
pushd content
mkdir en
mv _index.md post en
popd

Now add these lines to the config file:

contentDir = 'content/en'
defaultContentLanguage = 'en'
defaultContentLanguageInSubdir = false
enableMissingTranslationPlaceholders = true

Build the site and you’ll see that files are generated at the top level:

$ npm install
$ hugo --cleanDestinationDir && ls -ld public/[eip]*
Start building sites … 
hugo v0.92.2+extended darwin/amd64 BuildDate=unknown

                   | EN  
-------------------+-----
  Pages            |  9  
  Paginator pages  |  0  
  Non-page files   |  0  
  Static files     |  2  
  Processed images |  0  
  Aliases          |  0  
  Sitemaps         |  1  
  Cleaned          |  0  

Total in 642 ms
-rw-r--r--  1 chalin  staff   807 17 Feb 12:41 public/index.html
-rw-r--r--  1 chalin  staff  1284 17 Feb 12:41 public/index.xml
drwxr-xr-x  5 chalin  staff   160 17 Feb 12:41 public/post

Now add the content mount:

[[module.mounts]]
source = "content"
target = "content"

Rebuild:

$ npm i
$ hugo --cleanDestinationDir && ls -ld public/[eip]*
Start building sites … 
hugo v0.92.2+extended darwin/amd64 BuildDate=unknown

                   | EN  
-------------------+-----
  Pages            |  9  
  Paginator pages  |  0  
  Non-page files   |  0  
  Static files     |  2  
  Processed images |  0  
  Aliases          |  0  
  Sitemaps         |  1  
  Cleaned          |  0  

Total in 642 ms
drwxr-xr-x  5 chalin  staff   160 17 Feb 12:44 public/en
-rw-r--r--  1 chalin  staff   602 17 Feb 12:44 public/index.html
-rw-r--r--  1 chalin  staff  1290 17 Feb 12:44 public/index.xml
$ ls -l public/en
total 16
-rw-r--r--  1 chalin  staff   570 17 Feb 12:44 index.html
-rw-r--r--  1 chalin  staff  1296 17 Feb 12:44 index.xml
drwxr-xr-x  3 chalin  staff    96 17 Feb 12:44 post

Notice how the files have moved.

Unless I’m missing something, this is behaving as expected.

This:

[[module.mounts]]
source = "content"
target = "content"

Should override this:

contentDir = 'content/en'

To simplify:

git clone --single-branch -b hugo-forum-topic-37215 https://github.com/jmooring/hugo-testing hugo-forum-topic-37215
cd hugo-forum-topic-37215
hugo && tree public/

Result:

public/
├── post/
│   ├── test/
│   │   └── index.html
│   └── index.html
└── index.html

Now add this to config.toml:

[[module.mounts]]
source = "content"
target = "content"

And then this:

rm -rf public/ && hugo && tree public/

Produces this:

public/
├── foo/
│   ├── post/
│   │   └── test/
│   │       └── index.html
│   └── index.html
└── index.html

See https://gohugo.io/hugo-modules/configuration/#module-config-mounts

When the mounts config was introduced in Hugo 0.56.0, we were careful to preserve the existing staticDir and similar configuration to make sure all existing sites just continued to work. But you should not have both: if you add a mounts section you should remove the old staticDir etc. settings.

Darn! I missed that the side note was referring to contentDir too. Since it is so prevalently used for multilingual sites, maybe it is worth listing explicitly? If so, here’s a PR for that: Add explicit `contentDir` to module-config-mounts by chalin · Pull Request #1658 · gohugoio/hugoDocs · GitHub.

I guess that the proper way for me to handle my situation is to:

  • Delete the contentDir
  • Add the following config:
    [[module.mounts]]
    source = "content/en"
    target = "content"
    

My guess is that would be a clean way or retiring the contentDir param. Would you agree @jmooring? (I’m still trying to understand mounts.)

Thanks for your help in resolving this.

structure

content/
├── en/
│   ├── posts/
│   │   ├── post-1.md
│   │   └── post-2.md
│   └── _index.md
└── _index.md
other
└── articles/
    ├── article-1.md
    └── article-2.md

config.toml

[[module.mounts]]
source = 'content/en'
target = 'content'
lang = 'en'

[[module.mounts]]
source = 'other'
target = 'content'
lang = 'en'

renders

public/
├── articles/
│   ├── article-1/
│   │   └── index.html
│   ├── article-2/
│   │   └── index.html
│   └── index.html
├── posts/
│   ├── post-1/
│   │   └── index.html
│   ├── post-2/
│   │   └── index.html
│   └── index.html
└── index.html
3 Likes

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