aboutsummaryrefslogtreecommitdiffhomepage
path: root/hugolib/menu_test.go
diff options
context:
space:
mode:
authorJoe Mooring <[email protected]>2024-12-18 11:41:47 -0800
committerBjørn Erik Pedersen <[email protected]>2024-12-19 08:47:53 +0100
commitb3f32949cb089ae686af8548161fafc50869214b (patch)
treef892cf45a329abfa60385a9f6b6f776b20d7c6f0 /hugolib/menu_test.go
parent55ecd3a90e37b8d14651789a582d3b60c7dc4bd1 (diff)
downloadhugo-b3f32949cb089ae686af8548161fafc50869214b.tar.gz
hugo-b3f32949cb089ae686af8548161fafc50869214b.zip
hugolib: Fix fallbacks for menu entry Name and Title
Closes #13161
Diffstat (limited to 'hugolib/menu_test.go')
-rw-r--r--hugolib/menu_test.go94
1 files changed, 85 insertions, 9 deletions
diff --git a/hugolib/menu_test.go b/hugolib/menu_test.go
index 6ee62771b..3be999c31 100644
--- a/hugolib/menu_test.go
+++ b/hugolib/menu_test.go
@@ -252,9 +252,9 @@ menu:
`)
- b.WithTemplatesAdded("index.html", `{{ range .Site.Menus.main }}{{ .Title }}|Children:
+ b.WithTemplatesAdded("index.html", `{{ range .Site.Menus.main }}{{ .Title }}|Children:
{{- $children := sort .Children ".Page.Date" "desc" }}{{ range $children }}{{ .Title }}|{{ end }}{{ end }}
-
+
`)
b.Build(BuildCfg{})
@@ -272,11 +272,11 @@ func TestMenuParamsEmptyYaml(t *testing.T) {
b.WithContent("p1.md", `---
menus:
- main:
+ main:
identity: journal
weight: 2
params:
----
+---
`)
b.Build(BuildCfg{})
}
@@ -289,9 +289,9 @@ title = "Contact Us"
url = "mailto:[email protected]"
weight = 300
[menus.main.params]
-foo = "foo_config"
-key2 = "key2_config"
-camelCase = "camelCase_config"
+foo = "foo_config"
+key2 = "key2_config"
+camelCase = "camelCase_config"
`)
b.WithTemplatesAdded("index.html", `
@@ -343,7 +343,7 @@ weight = 1
pageRef = "/blog/post3"
title = "My Post 3"
url = "/blog/post3"
-
+
`)
commonTempl := `
@@ -519,7 +519,7 @@ Menu Item: {{ $i }}: {{ .Pre }}{{ .Name }}{{ .Post }}|{{ .URL }}|
b := Test(t, files)
b.AssertFileContent("public/index.html", `
-Menu Item: 0: <span>Home</span>|/|
+Menu Item: 0: <span>Home</span>|/|
`)
}
@@ -622,3 +622,79 @@ title: p3
b.AssertFileExists("public/index.html", true)
b.AssertFileContent("public/index.html", `<a href="/s1/p2/">p2</a><a href="/s1/">s1</a>`)
}
+
+// Issue 13161
+func TestMenuNameAndTitleFallback(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- hugo.toml --
+disableKinds = ['rss','sitemap','taxonomy','term']
+[[menus.main]]
+name = 'P1_ME_Name'
+title = 'P1_ME_Title'
+pageRef = '/p1'
+weight = 10
+[[menus.main]]
+pageRef = '/p2'
+weight = 20
+[[menus.main]]
+pageRef = '/p3'
+weight = 30
+[[menus.main]]
+name = 'S1_ME_Name'
+title = 'S1_ME_Title'
+pageRef = '/s1'
+weight = 40
+[[menus.main]]
+pageRef = '/s2'
+weight = 50
+[[menus.main]]
+pageRef = '/s3'
+weight = 60
+-- content/p1.md --
+---
+title: P1_Title
+---
+-- content/p2.md --
+---
+title: P2_Title
+---
+-- content/p3.md --
+---
+title: P3_Title
+linkTitle: P3_LinkTitle
+---
+-- content/s1/_index.md --
+---
+title: S1_Title
+---
+-- content/s2/_index.md --
+---
+title: S2_Title
+---
+-- content/s3/_index.md --
+---
+title: S3_Title
+linkTitle: S3_LinkTitle
+---
+-- layouts/_default/single.html --
+{{ .Content }}
+-- layouts/_default/list.html --
+{{ .Content }}
+-- layouts/_default/home.html --
+{{- range site.Menus.main }}
+URL: {{ .URL }}| Name: {{ .Name }}| Title: {{ .Title }}| PageRef: {{ .PageRef }}| Page.Title: {{ .Page.Title }}| Page.LinkTitle: {{ .Page.LinkTitle }}|
+{{- end }}
+`
+
+ b := Test(t, files)
+ b.AssertFileContent("public/index.html",
+ `URL: /p1/| Name: P1_ME_Name| Title: P1_ME_Title| PageRef: /p1| Page.Title: P1_Title| Page.LinkTitle: P1_Title|`,
+ `URL: /p2/| Name: P2_Title| Title: P2_Title| PageRef: /p2| Page.Title: P2_Title| Page.LinkTitle: P2_Title|`,
+ `URL: /p3/| Name: P3_LinkTitle| Title: P3_Title| PageRef: /p3| Page.Title: P3_Title| Page.LinkTitle: P3_LinkTitle|`,
+ `URL: /s1/| Name: S1_ME_Name| Title: S1_ME_Title| PageRef: /s1| Page.Title: S1_Title| Page.LinkTitle: S1_Title|`,
+ `URL: /s2/| Name: S2_Title| Title: S2_Title| PageRef: /s2| Page.Title: S2_Title| Page.LinkTitle: S2_Title|`,
+ `URL: /s3/| Name: S3_LinkTitle| Title: S3_Title| PageRef: /s3| Page.Title: S3_Title| Page.LinkTitle: S3_LinkTitle|`,
+ )
+}