Absolute paths in mounts

Hello!

I’m trying to use mounts in my main project with a configuration like this:

{
  "module":{
    "mounts":[
      {
        "source":"my-awesome-content",
        "target":"content"
      }
    ]
  }
}

And it works.

However if I try to use an absolute path in source like “C:\my-awesome-content” then it doesn’t work. Could it be an issue on Windows?

Has anybody had success with using absolute paths in mounts? :slight_smile:

/Regin

I’m not able to get absolute paths working either in Linux. Makes me wonder if the documentation is incorrect, or if there is a bug.

1 Like

Thanks for checking on Linux @b_rad! :pray:

I’ve opened an issue on Github here: https://github.com/gohugoio/hugo/issues/6622

1 Like

I was going to say this is probably a “Windows thing”, but then I saw Linux mentioned. It was intented to work… Not sure why it doesn’t, but I obviously didn’t add a test for it.

1 Like

One other possible bug that I noticed, is if you use a sub-directory for a target then it removes the default target unless you define it:

module:
  mounts:
  - source: test
    target: content/test

That will remove the default content target mount.

It must start with one of Hugo’s component folders: static , content , layouts , data , assets , i18n , or archetypes . E.g. content/blog .

Hi @bep.

I’ve taken a dive into the hugo source code and I discovered some logic in hugo/modules/collect.go that seems to prevent the absolute paths.

I’ve described it in issue #6622 mentioned above and also added some code that seems to fix the issue.

However I’m not that familiar with go or the hugo code base, so it’s probably not the right solution :sweat_smile:

That is as designed. If you have a mounts section – that is the full truth. For good reasons.

I don’t follow but it could be due to my own lack of understanding. If I was using the following I could understand why the content target would be overridden:

module:
  mounts:
  - source: test
    target: content

However, using the following doesn’t make sense to me why the default content target is removed:

module:
  mounts:
  - source: test
    target: content/test

It doesn’t overwrite all the default mounts when I do that, just the one that contains the first directory in the path.

  • We want one way and only one way to configure directories in Hugo
  • contentDir etc. is preserved just for backwards compability
  • Given your second configuration it would not be possible to tell Hugo that you want content/test and ONLY that directory if we also added some other default that may or not exist in your project.

So, if you have a module definition it must be complete.