shithub: hugo

Download patch

ref: 83c6806576a27942d49ff0cf81712b14bfda43e0
parent: c7f67dd63c60ef88cd76d8497abff864690919ed
author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
date: Sun Dec 11 08:01:11 EST 2016

Fix menu URL for node type pages

By delaying the menu assembly.

Fixes #2770

--- a/hugolib/node_as_page_test.go
+++ b/hugolib/node_as_page_test.go
@@ -430,6 +430,22 @@
 ---
 `)
 
+	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 @@
 		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 @@
 {{ 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 @@
 {{ 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 @@
 {{ 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" }}
 `)
@@ -688,6 +716,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" }}
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -1328,8 +1328,6 @@
 func (s *Site) buildSiteMeta() (err error) {
 	defer s.timerStep("build Site meta")
 
-	s.assembleMenus()
-
 	if len(s.Pages) == 0 {
 		return
 	}
@@ -1342,6 +1340,8 @@
 	}
 
 	s.assembleSections()
+
+	s.assembleMenus()
 
 	s.Info.LastChange = s.Pages[0].Lastmod