@@ -252,9 +252,9 @@ menu:
252252
253253` )
254254
255- b .WithTemplatesAdded ("index.html" , `{{ range .Site.Menus.main }}{{ .Title }}|Children:
255+ b .WithTemplatesAdded ("index.html" , `{{ range .Site.Menus.main }}{{ .Title }}|Children:
256256{{- $children := sort .Children ".Page.Date" "desc" }}{{ range $children }}{{ .Title }}|{{ end }}{{ end }}
257-
257+
258258` )
259259
260260 b .Build (BuildCfg {})
@@ -272,11 +272,11 @@ func TestMenuParamsEmptyYaml(t *testing.T) {
272272
273273 b .WithContent ("p1.md" , `---
274274menus:
275- main:
275+ main:
276276 identity: journal
277277 weight: 2
278278 params:
279- ---
279+ ---
280280` )
281281 b .Build (BuildCfg {})
282282}
@@ -289,9 +289,9 @@ title = "Contact Us"
289289url = "mailto:noreply@example.com"
290290weight = 300
291291[menus.main.params]
292- foo = "foo_config"
293- key2 = "key2_config"
294- camelCase = "camelCase_config"
292+ foo = "foo_config"
293+ key2 = "key2_config"
294+ camelCase = "camelCase_config"
295295` )
296296
297297 b .WithTemplatesAdded ("index.html" , `
@@ -343,7 +343,7 @@ weight = 1
343343pageRef = "/blog/post3"
344344title = "My Post 3"
345345url = "/blog/post3"
346-
346+
347347` )
348348
349349 commonTempl := `
@@ -519,7 +519,7 @@ Menu Item: {{ $i }}: {{ .Pre }}{{ .Name }}{{ .Post }}|{{ .URL }}|
519519 b := Test (t , files )
520520
521521 b .AssertFileContent ("public/index.html" , `
522- Menu Item: 0: <span>Home</span>|/|
522+ Menu Item: 0: <span>Home</span>|/|
523523` )
524524}
525525
@@ -622,3 +622,79 @@ title: p3
622622 b .AssertFileExists ("public/index.html" , true )
623623 b .AssertFileContent ("public/index.html" , `<a href="/s1/p2/">p2</a><a href="/s1/">s1</a>` )
624624}
625+
626+ // Issue 13161
627+ func TestMenuNameAndTitleFallback (t * testing.T ) {
628+ t .Parallel ()
629+
630+ files := `
631+ -- hugo.toml --
632+ disableKinds = ['rss','sitemap','taxonomy','term']
633+ [[menus.main]]
634+ name = 'P1_ME_Name'
635+ title = 'P1_ME_Title'
636+ pageRef = '/p1'
637+ weight = 10
638+ [[menus.main]]
639+ pageRef = '/p2'
640+ weight = 20
641+ [[menus.main]]
642+ pageRef = '/p3'
643+ weight = 30
644+ [[menus.main]]
645+ name = 'S1_ME_Name'
646+ title = 'S1_ME_Title'
647+ pageRef = '/s1'
648+ weight = 40
649+ [[menus.main]]
650+ pageRef = '/s2'
651+ weight = 50
652+ [[menus.main]]
653+ pageRef = '/s3'
654+ weight = 60
655+ -- content/p1.md --
656+ ---
657+ title: P1_Title
658+ ---
659+ -- content/p2.md --
660+ ---
661+ title: P2_Title
662+ ---
663+ -- content/p3.md --
664+ ---
665+ title: P3_Title
666+ linkTitle: P3_LinkTitle
667+ ---
668+ -- content/s1/_index.md --
669+ ---
670+ title: S1_Title
671+ ---
672+ -- content/s2/_index.md --
673+ ---
674+ title: S2_Title
675+ ---
676+ -- content/s3/_index.md --
677+ ---
678+ title: S3_Title
679+ linkTitle: S3_LinkTitle
680+ ---
681+ -- layouts/_default/single.html --
682+ {{ .Content }}
683+ -- layouts/_default/list.html --
684+ {{ .Content }}
685+ -- layouts/_default/home.html --
686+ {{- range site.Menus.main }}
687+ URL: {{ .URL }}| Name: {{ .Name }}| Title: {{ .Title }}| PageRef: {{ .PageRef }}| Page.Title: {{ .Page.Title }}| Page.LinkTitle: {{ .Page.LinkTitle }}|
688+ {{- end }}
689+ `
690+
691+ b := Test (t , files )
692+ b .AssertFileContent ("public/index.html" ,
693+ `URL: /p1/| Name: P1_ME_Name| Title: P1_ME_Title| PageRef: /p1| Page.Title: P1_Title| Page.LinkTitle: P1_Title|` ,
694+ `URL: /p2/| Name: P2_Title| Title: P2_Title| PageRef: /p2| Page.Title: P2_Title| Page.LinkTitle: P2_Title|` ,
695+ `URL: /p3/| Name: P3_LinkTitle| Title: P3_Title| PageRef: /p3| Page.Title: P3_Title| Page.LinkTitle: P3_LinkTitle|` ,
696+ `URL: /s1/| Name: S1_ME_Name| Title: S1_ME_Title| PageRef: /s1| Page.Title: S1_Title| Page.LinkTitle: S1_Title|` ,
697+ `URL: /s2/| Name: S2_Title| Title: S2_Title| PageRef: /s2| Page.Title: S2_Title| Page.LinkTitle: S2_Title|` ,
698+ `URL: /s3/| Name: S3_LinkTitle| Title: S3_Title| PageRef: /s3| Page.Title: S3_Title| Page.LinkTitle: S3_LinkTitle|` ,
699+ )
700+ }
0 commit comments