Mounting different branches/tags from the same repository

In my main repository (where I build Hugo) I am using module imports to pull in documentation (for an API) written in another remote repository. The documentation in the other repository is organised in a simple way, like this:

docs
--file1.md
--file2.md
--folder
----file1.md
----file2.md

The currently unreleased documentation in this “remote” repository is in “master” and already released dev is stored in a branch with a name that corresponds to the version of the API (i.e. “v3.4.0”). There are no version numbers in the “docs” folder.

I am specifying the “v3.4.0” branch of this remote repository in the go.mod file of my main repository, by using hugo mod get -u https://gitlab.com/org/repo.git@v3.4.x, this translates to a specific commit hash relating to that branch in the go.mod file.

Then, in hugo.toml, I use module.imports to specify the repository (without a branch name) and then module.imports.mount to mount the content of the “docs” folder where I need it, i.e. in a folder called “3.4”, like this:

  [[module.imports]]
    path="gitlab.com/org/repo"
  [[module.imports.mounts]]
    source = "docs"
    target = "content/api/3.4"

So, when the next release of this API doc is ready, in the remote repository it will be put in a branch called “v3.5.0” (for example). Then I will have a branch called “v3.4.0” and “v3.5.0”. I would then like to be able to pull in the files in the “v3.5.0” branch and mount them in my main doc repository in a folder called “3.5” (as well as pulling in the files in the v3.4.0 branch and putting them in a folder called “3.4”).

However, I cannot find a way to do this and I am unsure it is even possible. I had thought about specifying each branch in go.mod but that doesn’t work as hugo mod get just overwrites the entry for the repository instead of appending an additional one. It looks like you can only specify a repository once in go.mod. And it seems it’s not possible to specify branches in mount.imports either.

The only way I could see this working is to create the 3.4 and 3.5 folders in the remote repository and mount them via hugo.toml, but I’m trying to avoid doing that.

Are there any other options within Hugo that would allow me to do what I am trying to do?

1 Like
2 Likes

Wow, thank you. I didn’t expect that, I will follow with interest.

Getting the first working version up and running was surprisingly straight forward – and it works pretty good in my tests. There are some missing pieces to get this over the finish line, but it should not take too long:

1 Like

Again that is amazing! Thank you for your efforts…!

1 Like

Oh gosh that was quick - thank you so much - really appreciate the blazing fast turn around (as quick as Hugo builds!!).

I’ll be upgrading from 0.147.5 to 0.150.0 tomorrow. It will be used here if you’re interested: Imaging API v3 | Documentation

1 Like

Well, hat’s off to you @bep it works flawlessly and is so easy to configure.

hugo.toml:

  [[module.imports]]
    path="gitlab.com/castdoc/imaging-api"
    version="v3.4.x"
  [[module.imports.mounts]]
    source = "docs"
    target = "content/api-test/3.4"
  [[module.imports]]
    path="gitlab.com/castdoc/imaging-api"
    version="master"
  [[module.imports.mounts]]
    source = "docs"
    target = "content/api-test/3.5"

Built with Cloudflare: Imaging API - 3.4 | Documentation (I just need to bump the version number for the 3.5 files from 3.4 to 3.5)…

Brilliant! Thank you!

2 Likes

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