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()
// 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)
}