gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.98k stars 7.54k forks source link

Module menus not respected #12584

Open fmunteanu opened 5 months ago

fmunteanu commented 5 months ago

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.126.1+extended darwin/arm64 BuildDate=2024-05-15T10:42:34Z VendorInfo=brew

Does this issue reproduce with the latest release?

Yes.

Current Issue

I've been struggling with this issue for a while, without any resolution. The discussion started on forums did not yield any positive outcome, so I'm reaching at Hugo developers, to determine if my end-goal is achievable with Hugo.

My current Hugo website consists of following files structure, see testing repository:

$ tree -d -L 3
.
├── docs -- FRONTPAGE
│   ├── content
│   └── static
│       └── images
├── global -- Imported MODULE, storing all common settings
│   ├── i18n
│   └── layouts
│       ├── partials
│       └── shortcodes
└── project -- Imported MODULE, storing the /docs/project sub-project with unique title and menus
    ├── content
    │   ├── tutorials
    │   └── wiki
    └── static
        └── images

My goal is to have specific website titles and menus imported from Hugo modules, at build time. In other words, when I build the website, I expect the following end-result:

Thank you for providing feedback to my current issue.

bep commented 5 months ago

There's two aspects of this:

  1. The default merge strategy of menus is shallow (see https://gohugo.io/getting-started/configuration/#merge-configuration-from-themes). You can change that in your project setting ... but:
  2. When merging configurations, we do not merge slices (which is the main menu in your example). This has been discussed, but that cannot be done without additional information.
fmunteanu commented 5 months ago

@bep thank you for the response. From your perspective, what changes should I apply to hugo.yaml, in order to achieve the intended result? I even tried changing from menus.main to menus.project (see PR) but Hugo does not understand the differences, at build time, propagating the new menus everywhere, instead of seeing them unique only for /docs/project directory, as intended. I believe this is happening because Hugo combines all imported module configurations and picks the last found values.

The navbar.html template uses a $menu variable to easily determine the correct menu used. Do I need a specific module.mounts definition?

bep commented 5 months ago

I believe this is happening because Hugo combines all imported module configurations and picks the last found values.

With merge strategy shallow (which is the deep), Hugo walks the dependency tree starting from the project and merges the menu configurations shallowly, the first entry wins.

So, if you have project -> module1 -> module2

And

We use project.{a,b}, module1.b and module2.d.

I'm pretty sure that works as described.

fmunteanu commented 5 months ago

@bep I'm still not sure what changes I need to perform, in order to achieve the scoped end-results. Right now I have the following mounts on /project/hugo.yaml module:

module:
  mounts:
    - source: content
      target: content/project
    - source: layouts
      target: layouts/project
    - source: public
      target: public/project
    - source: static
      target: static/project

While executing the build command at the root of repository:

hugo --gc --minify -s ./docs

The end-result should be: