Repository: gohugoio/hugo (language: go)

Issue:
v0.112.6 - The .URL menu variable ignores the  baseURL subdirectory
config

```toml
baseURL = "https://example.org/foo/"

[[menu.main]]
name = 'Posts'
url = '/posts'
```

template

```
{{ warnf "%s" (index site.Menus.main 0).URL }}
```

v0.111.3 --> `/foo/posts`  (CORRECT)
v0.112.6 --> `/posts`

This is not an issue if you specify `pageRef` instead of `url` in the menu entry definition, but I suspect (unfortunately) that the vast majority of live sites use `url` instead of `pageRef`.




Related: <https://discourse.gohugo.io/t/issue-with-baseurl-in-0-112-0-0-112-6/44656/>


Discussion / hints:

Fix patch:
diff --git a/hugolib/site.go b/hugolib/site.go
index d23a903856e..035f543ee2c 100644
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -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)
 			}
 
@@ -1064,7 +1066,7 @@ func (s *Site) renderAndWritePage(statCounter *uint64, name string, targetPath s
 			pd.AbsURLPath = s.absURLPath(targetPath)
 		}
 
-		if s.watching() && s.conf.Internal.Watch && !s.conf.Internal.DisableLiveReload {
+		if s.watching() && s.conf.Internal.Running && !s.conf.Internal.DisableLiveReload {
 			pd.LiveReloadBaseURL = s.Conf.BaseURLLiveReload().URL()
 		}
 


Test patch:
diff --git a/hugolib/menu_test.go b/hugolib/menu_test.go
index 751608246bb..810b9fe2008 100644
--- a/hugolib/menu_test.go
+++ b/hugolib/menu_test.go
@@ -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|
+`)
+
+}
diff --git a/testscripts/commands/hugo__watch.txt b/testscripts/commands/hugo__watch.txt
index b434bd112ad..aa5201c5666 100644
--- a/testscripts/commands/hugo__watch.txt
+++ b/testscripts/commands/hugo__watch.txt
@@ -11,6 +11,7 @@ grep 'P1start' public/p1/index.html
 replace content/p1.md 'P1start' 'P1end'
 sleep 2
 grep 'P1end' public/p1/index.html
+! grep 'livereload' public/p1/index.html
 
 stop