Skip to content

Commit

Permalink
Fix menuItem.URL when pageRef is not set
Browse files Browse the repository at this point in the history
Fixes #11062
  • Loading branch information
bep committed Jun 2, 2023
1 parent a191b38 commit 5e5ce00
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
32 changes: 32 additions & 0 deletions hugolib/menu_test.go
Expand Up @@ -621,3 +621,35 @@ Menu Item: 0: <span>Home</span>|/|
`)

}

// Issue #11062
func TestMenusSubDirInBaseURL(t *testing.T) {
t.Parallel()

files := `
-- hugo.toml --
baseURL = "https://example.com/foo/"
title = "Hugo Menu Test"
[menus]
[[menus.main]]
name = "Posts"
url = "/posts"
weight = 1
-- layouts/index.html --
{{ range $i, $e := site.Menus.main }}
Menu Item: {{ $i }}|{{ .URL }}|
{{ end }}
`

b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()

b.AssertFileContent("public/index.html", `
Menu Item: 0|/foo/posts|
`)

}
4 changes: 3 additions & 1 deletion hugolib/site.go
Expand Up @@ -789,8 +789,10 @@ func (s *Site) assembleMenus() {
navigation.SetPageValues(me, p)
}
}
}

} else {
// If page is still nill, we must make sure that we have a URL that considers baseURL etc.
if types.IsNil(me.Page) {
me.ConfiguredURL = s.createNodeMenuEntryURL(me.MenuConfig.URL)
}

Expand Down

0 comments on commit 5e5ce00

Please sign in to comment.