Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module menus not respected #12584

Open
fmunteanu opened this issue Jun 8, 2024 · 4 comments
Open

Module menus not respected #12584

fmunteanu opened this issue Jun 8, 2024 · 4 comments

Comments

@fmunteanu
Copy link

fmunteanu commented Jun 8, 2024

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:

  • /docs should display the menus present into /docs/hugo.yaml
  • /docs/project should display the menus present into /project/hugo.yaml

Thank you for providing feedback to my current issue.

@bep
Copy link
Member

bep commented Jun 11, 2024

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.

@bep bep added this to the v0.128.0 milestone Jun 11, 2024
@fmunteanu
Copy link
Author

fmunteanu commented Jun 11, 2024

@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
Copy link
Member

bep commented Jun 12, 2024

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

  • project defines menu with keys a, b
  • module1 defines b, c
  • module2 defines b, c, d

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

I'm pretty sure that works as described.

@fmunteanu
Copy link
Author

fmunteanu commented Jun 12, 2024

@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:

@bep bep modified the milestones: v0.128.0, v0.129.0 Jun 21, 2024
@bep bep modified the milestones: v0.129.0, v0.131.0 Jul 22, 2024
@bep bep modified the milestones: v0.131.0, v0.133.0 Aug 9, 2024
@bep bep modified the milestones: v0.133.0, Unscheduled Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants