@@ -252,9 +252,9 @@ menu:
252
252
253
253
` )
254
254
255
- b .WithTemplatesAdded ("index.html" , `{{ range .Site.Menus.main }}{{ .Title }}|Children:
255
+ b .WithTemplatesAdded ("index.html" , `{{ range .Site.Menus.main }}{{ .Title }}|Children:
256
256
{{- $children := sort .Children ".Page.Date" "desc" }}{{ range $children }}{{ .Title }}|{{ end }}{{ end }}
257
-
257
+
258
258
` )
259
259
260
260
b .Build (BuildCfg {})
@@ -272,11 +272,11 @@ func TestMenuParamsEmptyYaml(t *testing.T) {
272
272
273
273
b .WithContent ("p1.md" , `---
274
274
menus:
275
- main:
275
+ main:
276
276
identity: journal
277
277
weight: 2
278
278
params:
279
- ---
279
+ ---
280
280
` )
281
281
b .Build (BuildCfg {})
282
282
}
@@ -289,9 +289,9 @@ title = "Contact Us"
289
289
url = "mailto:noreply@example.com"
290
290
weight = 300
291
291
[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"
295
295
` )
296
296
297
297
b .WithTemplatesAdded ("index.html" , `
@@ -343,7 +343,7 @@ weight = 1
343
343
pageRef = "/blog/post3"
344
344
title = "My Post 3"
345
345
url = "/blog/post3"
346
-
346
+
347
347
` )
348
348
349
349
commonTempl := `
@@ -519,7 +519,7 @@ Menu Item: {{ $i }}: {{ .Pre }}{{ .Name }}{{ .Post }}|{{ .URL }}|
519
519
b := Test (t , files )
520
520
521
521
b .AssertFileContent ("public/index.html" , `
522
- Menu Item: 0: <span>Home</span>|/|
522
+ Menu Item: 0: <span>Home</span>|/|
523
523
` )
524
524
}
525
525
@@ -622,3 +622,77 @@ title: p3
622
622
b .AssertFileExists ("public/index.html" , true )
623
623
b .AssertFileContent ("public/index.html" , `<a href="/s1/p2/">p2</a><a href="/s1/">s1</a>` )
624
624
}
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_Name'
635
+ pageRef = '/p1'
636
+ weight = 10
637
+ [[menus.main]]
638
+ pageRef = '/p2'
639
+ weight = 20
640
+ [[menus.main]]
641
+ pageRef = '/p3'
642
+ weight = 30
643
+ [[menus.main]]
644
+ name = 'S1_Name'
645
+ pageRef = '/s1'
646
+ weight = 40
647
+ [[menus.main]]
648
+ pageRef = '/s2'
649
+ weight = 50
650
+ [[menus.main]]
651
+ pageRef = '/s3'
652
+ weight = 60
653
+ -- content/p1.md --
654
+ ---
655
+ title: P1_Title
656
+ ---
657
+ -- content/p2.md --
658
+ ---
659
+ title: P2_Title
660
+ ---
661
+ -- content/p3.md --
662
+ ---
663
+ title: P3_Title
664
+ linkTitle: P3_LinkTitle
665
+ ---
666
+ -- content/s1/_index.md --
667
+ ---
668
+ title: S1_Title
669
+ ---
670
+ -- content/s2/_index.md --
671
+ ---
672
+ title: S2_Title
673
+ ---
674
+ -- content/s3/_index.md --
675
+ ---
676
+ title: S3_Title
677
+ linkTitle: S3_LinkTitle
678
+ ---
679
+ -- layouts/_default/single.html --
680
+ {{ .Content }}
681
+ -- layouts/_default/list.html --
682
+ {{ .Content }}
683
+ -- layouts/_default/home.html --
684
+ {{- range $i, $_ := site.Menus.main }}
685
+ URL: {{ .URL }}| Name: {{ .Name }}| Title: {{ .Title }}| PageRef: {{ .PageRef }}| Page.Title: {{ .Page.Title }}| Page.LinkTitle: {{ .Page.LinkTitle }}|
686
+ {{- end }}
687
+ `
688
+
689
+ b := Test (t , files )
690
+ b .AssertFileContent ("public/index.html" ,
691
+ `URL: /p1/| Name: P1_Name| Title: P1_Title| PageRef: /p1| Page.Title: P1_Title| Page.LinkTitle: P1_Title|` ,
692
+ `URL: /p2/| Name: P2_Title| Title: P2_Title| PageRef: /p2| Page.Title: P2_Title| Page.LinkTitle: P2_Title|` ,
693
+ `URL: /p3/| Name: P3_LinkTitle| Title: P3_Title| PageRef: /p3| Page.Title: P3_Title| Page.LinkTitle: P3_LinkTitle|` ,
694
+ `URL: /s1/| Name: S1_Name| Title: S1_Title| PageRef: /s1| Page.Title: S1_Title| Page.LinkTitle: S1_Title|` ,
695
+ `URL: /s2/| Name: S2_Title| Title: S2_Title| PageRef: /s2| Page.Title: S2_Title| Page.LinkTitle: S2_Title|` ,
696
+ `URL: /s3/| Name: S3_LinkTitle| Title: S3_Title| PageRef: /s3| Page.Title: S3_Title| Page.LinkTitle: S3_LinkTitle|` ,
697
+ )
698
+ }
0 commit comments