]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Fix menu pageRef resolution in multidimensional setups
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 25 Feb 2026 16:35:20 +0000 (17:35 +0100)
committerGitHub <noreply@github.com>
Wed, 25 Feb 2026 16:35:20 +0000 (17:35 +0100)
Fixes #14566

hugolib/menu_test.go
hugolib/site.go

index 2b9e5d9fb6bbeae7fe0d6caa6b099d87bae5273b..20d862caa692393977231525c76d267cd9e95f50 100644 (file)
@@ -604,6 +604,40 @@ title: p3
        b.AssertFileContent("public/index.html", `<a href="/s1/p2/">p2</a><a href="/s1/">s1</a>`)
 }
 
+// Issue 14566
+func TestMenusPageRefSitesMatrix(t *testing.T) {
+       t.Parallel()
+
+       files := `
+-- hugo.toml --
+baseURL = "http://example.com/"
+defaultContentVersionInSubdir = true
+[versions]
+[versions.v1]
+[versions.v2]
+
+[[menus.main]]
+name = "Home"
+pageRef = "/"
+weight = 1
+
+-- layouts/home.html --
+{{ range .Site.Menus.main }}
+{{ .Name }}|{{ .URL }}|{{ .Page.Path }}|{{ .Page.Site.Version.Name }}
+{{ end }}
+`
+
+       b := Test(t, files)
+
+       b.AssertFileContent("public/v1/index.html", `
+Home|/v1/|/|v1
+`)
+
+       b.AssertFileContent("public/v2/index.html", `
+Home|/v2/|/|v2
+`)
+}
+
 // Issue 13161
 func TestMenuNameAndTitleFallback(t *testing.T) {
        t.Parallel()
index 94e4cf5664e00b1332d5ddefaa0687f2a28e3ad0..07fe41d2a0fa5e2f2027ba6194a70d57c37e1638 100644 (file)
@@ -1403,8 +1403,12 @@ func (s *Site) assembleMenus() (navigation.Menus, error) {
 
        // add menu entries from config to flat hash
        for name, menu := range s.conf.Menus.Config {
-               for _, me := range menu {
-                       if types.IsNil(me.Page) && me.PageRef != "" {
+               for _, x := range menu {
+                       // Shallow copy the menu entry, so we can set the URL and page without modifying the config.
+                       c := *x
+                       me := &c
+
+                       if me.PageRef != "" {
                                // Try to resolve the page.
                                me.Page, _ = s.getPage(nil, me.PageRef)
                        }