commit 83c6806576a27942d49ff0cf81712b14bfda43e0
parent c7f67dd63c60ef88cd76d8497abff864690919ed
Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date: Sun, 11 Dec 2016 13:01:11 +0100
Fix menu URL for node type pages
By delaying the menu assembly.
Fixes #2770
Diffstat:
2 files changed, 37 insertions(+), 4 deletions(-)
diff --git a/hugolib/node_as_page_test.go b/hugolib/node_as_page_test.go
@@ -430,6 +430,22 @@ menu:
---
`)
+ writeSource(t, filepath.Join("content", "sect1", "_index.md"), `---
+title: Sect1 With Menu
+menu:
+ mymenu:
+ name: "Go Sect1!"
+---
+`)
+
+ writeSource(t, filepath.Join("content", "categories", "hugo", "_index.md"), `---
+title: Taxonomy With Menu
+menu:
+ mymenu:
+ name: "Go Tax Hugo!"
+---
+`)
+
viper.Set("paginate", 1)
viper.Set("title", "Hugo Rocks!")
@@ -439,7 +455,9 @@ menu:
t.Fatalf("Failed to build site: %s", err)
}
- assertFileContent(t, filepath.Join("public", "index.html"), true, "Home With Menu", "Menu Item: Go Home!")
+ assertFileContent(t, filepath.Join("public", "index.html"), true, "Home With Menu", "Home Menu Item: Go Home!: /")
+ assertFileContent(t, filepath.Join("public", "sect1", "index.html"), true, "Sect1 With Menu", "Section Menu Item: Go Sect1!: /sect1/")
+ assertFileContent(t, filepath.Join("public", "categories", "hugo", "index.html"), true, "Taxonomy With Menu", "Taxonomy Menu Item: Go Tax Hugo!: /categories/hugo/")
}
@@ -644,7 +662,7 @@ Index Content: {{ .Content }}
{{ end }}
{{ with .Site.Menus.mymenu }}
{{ range . }}
-Menu Item: {{ .Name }}
+Home Menu Item: {{ .Name }}: {{ .URL }}
{{ end }}
{{ end }}
Date: {{ .Date.Format "2006-01-02" }}
@@ -666,6 +684,11 @@ Section Content: {{ .Content }}
{{ range .Paginator.Pages }}
Pag: {{ .Title }}
{{ end }}
+{{ with .Site.Menus.mymenu }}
+{{ range . }}
+Section Menu Item: {{ .Name }}: {{ .URL }}
+{{ end }}
+{{ end }}
Date: {{ .Date.Format "2006-01-02" }}
Lastmod: {{ .Lastmod.Format "2006-01-02" }}
`)
@@ -678,6 +701,11 @@ Taxonomy Content: {{ .Content }}
{{ range .Paginator.Pages }}
Pag: {{ .Title }}
{{ end }}
+{{ with .Site.Menus.mymenu }}
+{{ range . }}
+Taxonomy Menu Item: {{ .Name }}: {{ .URL }}
+{{ end }}
+{{ end }}
Date: {{ .Date.Format "2006-01-02" }}
Lastmod: {{ .Lastmod.Format "2006-01-02" }}
`)
@@ -689,6 +717,11 @@ Taxonomy Terms Content: {{ .Content }}
{{ range $key, $value := .Data.Terms }}
k/v: {{ $key }} / {{ printf "%s" $value }}
{{ end }}
+{{ with .Site.Menus.mymenu }}
+{{ range . }}
+Taxonomy Terms Menu Item: {{ .Name }}: {{ .URL }}
+{{ end }}
+{{ end }}
Date: {{ .Date.Format "2006-01-02" }}
Lastmod: {{ .Lastmod.Format "2006-01-02" }}
`)
diff --git a/hugolib/site.go b/hugolib/site.go
@@ -1328,8 +1328,6 @@ func readCollator(s *Site, results <-chan HandledResult, errs chan<- error) {
func (s *Site) buildSiteMeta() (err error) {
defer s.timerStep("build Site meta")
- s.assembleMenus()
-
if len(s.Pages) == 0 {
return
}
@@ -1343,6 +1341,8 @@ func (s *Site) buildSiteMeta() (err error) {
s.assembleSections()
+ s.assembleMenus()
+
s.Info.LastChange = s.Pages[0].Lastmod
return