Debian Codegraph @

hugolib/pagecollections_test.go

raw
1 // Copyright 2025 The Hugo Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 package hugolib
15
16 import (
17 "fmt"
18 "path/filepath"
19 "testing"
20
21 qt "github.com/frankban/quicktest"
22 "github.com/gohugoio/hugo/resources/kinds"
23 "github.com/gohugoio/hugo/resources/page"
24 )
25
26 type getPageTest struct {
27 name string
28 kind string
29 context page.Page
30 pathVariants []string
31 expectedTitle string
32 }
33
34 func (t *getPageTest) check(p page.Page, err error, errorMsg string, c *qt.C) {
35 c.Helper()
36 errorComment := qt.Commentf(errorMsg)
37 switch t.kind {
38 case "Ambiguous":
39 c.Assert(err, qt.Not(qt.IsNil))
40 c.Assert(p, qt.IsNil, errorComment)
41 case "NoPage":
42 c.Assert(err, qt.IsNil)
43 c.Assert(p, qt.IsNil, errorComment)
44 default:
45 c.Assert(err, qt.IsNil, errorComment)
46 c.Assert(p, qt.Not(qt.IsNil), errorComment)
47 c.Assert(p.Kind(), qt.Equals, t.kind, errorComment)
48 c.Assert(p.Title(), qt.Equals, t.expectedTitle, errorComment)
49 }
50 }
51
52 func TestGetPage(t *testing.T) {
53 t.Parallel()
54
55 files := `
56 -- hugo.toml --
57 -- layouts/single.html --
58 {{ .Title }}
59 -- layouts/list.html --
60 {{ .Title }}
61
62 -- content/_index.md --
63 ---
64 title: "home page"
65 categories:
66 - Hugo
67 ---
68 # Doc
69
70 -- content/about.md --
71 ---
72 title: "about page"
73 categories:
74 - Hugo
75 ---
76 # Doc
77
78 -- content/sect0/page1.md --
79 ---
80 title: "Title0_1"
81 categories:
82 - Hugo
83 ---
84 # Doc
85
86 -- content/sect1/page1.md --
87 ---
88 title: "Title1_1"
89 categories:
90 - Hugo
91 ---
92 # Doc
93
94 -- content/sect2/_index.md --
95 ---
96 title: "Section 2"
97 categories:
98 - Hugo
99 ---
100 # Doc
101
102 -- content/sect3/_index.md --
103 ---
104 title: "section 3"
105 categories:
106 - Hugo
107 ---
108 # Doc
109
110 -- content/sect3/page1.md --
111 ---
112 title: "Title3_1"
113 categories:
114 - Hugo
115 ---
116 # Doc
117
118 -- content/sect3/unique.md --
119 ---
120 title: "UniqueBase"
121 categories:
122 - Hugo
123 ---
124 # Doc
125
126 -- content/sect3/Unique2.md --
127 ---
128 title: "UniqueBase2"
129 categories:
130 - Hugo
131 ---
132 # Doc
133
134 -- content/sect3/sect7/_index.md --
135 ---
136 title: "another sect7"
137 categories:
138 - Hugo
139 ---
140 # Doc
141
142 -- content/sect3/subsect/deep.md --
143 ---
144 title: "deep page"
145 categories:
146 - Hugo
147 ---
148 # Doc
149
150 -- content/sect3/b1/index.md --
151 ---
152 title: "b1 bundle"
153 categories:
154 - Hugo
155 ---
156 # Doc
157
158 -- content/sect3/index/index.md --
159 ---
160 title: "index bundle"
161 categories:
162 - Hugo
163 ---
164 # Doc
165
166 -- content/sect4/page2.md --
167 ---
168 title: "Title4_2"
169 categories:
170 - Hugo
171 ---
172 # Doc
173
174 -- content/sect5/page3.md --
175 ---
176 title: "Title5_3"
177 categories:
178 - Hugo
179 ---
180 # Doc
181
182 -- content/sect7/somesubpage.md --
183 ---
184 title: "Some Sub Page in Sect7"
185 categories:
186 - Hugo
187 ---
188 # Doc
189
190 -- content/sect7/page9.md --
191 ---
192 title: "Title7_9"
193 categories:
194 - Hugo
195 ---
196 # Doc
197
198 -- content/section_bundle_overlap/_index.md --
199 ---
200 title: "index overlap section"
201 categories:
202 - Hugo
203 ---
204 # Doc
205
206 -- content/section_bundle_overlap_bundle/index.md --
207 ---
208 title: "index overlap bundle"
209 categories:
210 - Hugo
211 ---
212 # Doc
213 `
214
215 b := Test(t, files)
216
217 s := b.H.Sites[0]
218
219 sec3, err := s.getPage(nil, "/sect3")
220 b.Assert(err, qt.IsNil)
221 b.Assert(sec3, qt.Not(qt.IsNil))
222
223 tests := []getPageTest{
224 // legacy content root relative paths
225 {"Root relative, no slash, home", kinds.KindHome, nil, []string{""}, "home page"},
226 {"Root relative, no slash, root page", kinds.KindPage, nil, []string{"about.md", "ABOUT.md"}, "about page"},
227 {"Root relative, no slash, section", kinds.KindSection, nil, []string{"sect3"}, "section 3"},
228 {"Root relative, no slash, section page", kinds.KindPage, nil, []string{"sect3/page1.md"}, "Title3_1"},
229 {"Root relative, no slash, sub section", kinds.KindSection, nil, []string{"sect3/sect7"}, "another sect7"},
230 {"Root relative, no slash, nested page", kinds.KindPage, nil, []string{"sect3/subsect/deep.md"}, "deep page"},
231 {"Root relative, no slash, OS slashes", kinds.KindPage, nil, []string{filepath.FromSlash("sect5/page3.md")}, "Title5_3"},
232
233 {"Short ref, unique", kinds.KindPage, nil, []string{"unique.md", "unique"}, "UniqueBase"},
234 {"Short ref, unique, upper case", kinds.KindPage, nil, []string{"Unique2.md", "unique2.md", "unique2"}, "UniqueBase2"},
235 {"Short ref, ambiguous", "Ambiguous", nil, []string{"page1.md"}, ""},
236
237 // ISSUE: This is an ambiguous ref, but because we have to support the legacy
238 // content root relative paths without a leading slash, the lookup
239 // returns /sect7. This undermines ambiguity detection, but we have no choice.
240 //{"Ambiguous", nil, []string{"sect7"}, ""},
241 {"Section, ambiguous", kinds.KindSection, nil, []string{"sect7"}, "Sect7s"},
242
243 {"Absolute, home", kinds.KindHome, nil, []string{"/", ""}, "home page"},
244 {"Absolute, page", kinds.KindPage, nil, []string{"/about.md", "/about"}, "about page"},
245 {"Absolute, sect", kinds.KindSection, nil, []string{"/sect3"}, "section 3"},
246 {"Absolute, page in subsection", kinds.KindPage, nil, []string{"/sect3/page1.md", "/Sect3/Page1.md"}, "Title3_1"},
247 {"Absolute, section, subsection with same name", kinds.KindSection, nil, []string{"/sect3/sect7"}, "another sect7"},
248 {"Absolute, page, deep", kinds.KindPage, nil, []string{"/sect3/subsect/deep.md"}, "deep page"},
249 {"Absolute, page, OS slashes", kinds.KindPage, nil, []string{filepath.FromSlash("/sect5/page3.md")}, "Title5_3"}, // test OS-specific path
250 {"Absolute, unique", kinds.KindPage, nil, []string{"/sect3/unique.md"}, "UniqueBase"},
251 {"Absolute, unique, case", kinds.KindPage, nil, []string{"/sect3/Unique2.md", "/sect3/unique2.md", "/sect3/unique2", "/sect3/Unique2"}, "UniqueBase2"},
252 // next test depends on this page existing
253 // {"NoPage", nil, []string{"/unique.md"}, ""}, // ISSUE #4969: this is resolving to /sect3/unique.md
254 {"Absolute, missing page", "NoPage", nil, []string{"/missing-page.md"}, ""},
255 {"Absolute, missing section", "NoPage", nil, []string{"/missing-section"}, ""},
256
257 // relative paths
258 {"Dot relative, home", kinds.KindHome, sec3, []string{".."}, "home page"},
259 {"Dot relative, home, slash", kinds.KindHome, sec3, []string{"../"}, "home page"},
260 {"Dot relative about", kinds.KindPage, sec3, []string{"../about.md"}, "about page"},
261 {"Dot", kinds.KindSection, sec3, []string{"."}, "section 3"},
262 {"Dot slash", kinds.KindSection, sec3, []string{"./"}, "section 3"},
263 {"Page relative, no dot", kinds.KindPage, sec3, []string{"page1.md"}, "Title3_1"},
264 {"Page relative, dot", kinds.KindPage, sec3, []string{"./page1.md"}, "Title3_1"},
265 {"Up and down another section", kinds.KindPage, sec3, []string{"../sect4/page2.md"}, "Title4_2"},
266 {"Rel sect7", kinds.KindSection, sec3, []string{"sect7"}, "another sect7"},
267 {"Rel sect7 dot", kinds.KindSection, sec3, []string{"./sect7"}, "another sect7"},
268 {"Dot deep", kinds.KindPage, sec3, []string{"./subsect/deep.md"}, "deep page"},
269 {"Dot dot inner", kinds.KindPage, sec3, []string{"./subsect/../../sect7/page9.md"}, "Title7_9"},
270 {"Dot OS slash", kinds.KindPage, sec3, []string{filepath.FromSlash("../sect5/page3.md")}, "Title5_3"}, // test OS-specific path
271 {"Dot unique", kinds.KindPage, sec3, []string{"./unique.md"}, "UniqueBase"},
272 {"Dot sect", "NoPage", sec3, []string{"./sect2"}, ""},
273 //{"NoPage", sec3, []string{"sect2"}, ""}, // ISSUE: /sect3 page relative query is resolving to /sect2
274
275 {"Abs, ignore context, home", kinds.KindHome, sec3, []string{"/"}, "home page"},
276 {"Abs, ignore context, about", kinds.KindPage, sec3, []string{"/about.md"}, "about page"},
277 {"Abs, ignore context, page in section", kinds.KindPage, sec3, []string{"/sect4/page2.md"}, "Title4_2"},
278 {"Abs, ignore context, page subsect deep", kinds.KindPage, sec3, []string{"/sect3/subsect/deep.md"}, "deep page"}, // next test depends on this page existing
279 {"Abs, ignore context, page deep", "NoPage", sec3, []string{"/subsect/deep.md"}, ""},
280
281 // Taxonomies
282 {"Taxonomy term", kinds.KindTaxonomy, nil, []string{"categories"}, "Categories"},
283 {"Taxonomy", kinds.KindTerm, nil, []string{"categories/hugo", "categories/Hugo"}, "Hugo"},
284
285 // Bundle variants
286 {"Bundle regular", kinds.KindPage, nil, []string{"sect3/b1", "sect3/b1/index.md", "sect3/b1/index.en.md"}, "b1 bundle"},
287 {"Bundle index name", kinds.KindPage, nil, []string{"sect3/index/index.md", "sect3/index"}, "index bundle"},
288
289 // https://github.com/gohugoio/hugo/issues/7301
290 {"Section and bundle overlap", kinds.KindPage, nil, []string{"section_bundle_overlap_bundle"}, "index overlap bundle"},
291 }
292
293 for _, test := range tests {
294 b.Run(test.name, func(c *qt.C) {
295 errorMsg := fmt.Sprintf("Test case %v %v -> %s", test.context, test.pathVariants, test.expectedTitle)
296
297 // test legacy public Site.GetPage (which does not support page context relative queries)
298 if test.context == nil {
299 for _, ref := range test.pathVariants {
300 args := append([]string{test.kind}, ref)
301 page, err := s.GetPage(args...)
302 test.check(page, err, errorMsg, c)
303 }
304 }
305
306 // test new internal Site.getPage
307 for _, ref := range test.pathVariants {
308 page2, err := s.getPage(test.context, ref)
309 test.check(page2, err, errorMsg, c)
310 }
311 })
312 }
313 }
314
315 // #11664
316 func TestGetPageIndexIndex(t *testing.T) {
317 files := `
318 -- hugo.toml --
319 disableKinds = ["taxonomy", "term"]
320 -- content/mysect/index/index.md --
321 ---
322 title: "Mysect Index"
323 ---
324 -- layouts/home.html --
325 GetPage 1: {{ with site.GetPage "mysect/index/index.md" }}{{ .Title }}|{{ .RelPermalink }}|{{ .Path }}{{ end }}|
326 GetPage 2: {{ with site.GetPage "mysect/index" }}{{ .Title }}|{{ .RelPermalink }}|{{ .Path }}{{ end }}|
327 `
328
329 b := Test(t, files)
330 b.AssertFileContent("public/index.html",
331 "GetPage 1: Mysect Index|/mysect/index/|/mysect/index|",
332 "GetPage 2: Mysect Index|/mysect/index/|/mysect/index|",
333 )
334 }
335
336 // https://github.com/gohugoio/hugo/issues/6034
337 func TestGetPageRelative(t *testing.T) {
338 files := `
339 -- hugo.toml --
340 -- content/what/_index.md --
341 ---title: what
342 ---
343 -- content/what/members.md --
344 ---title: members what
345 draft: false
346 ---
347 -- content/where/_index.md --
348 ---title: where
349 ---
350 -- content/where/members.md --
351 ---title: members where
352 draft: false
353 ---
354 -- content/who/_index.md --
355 ---title: who
356 ---
357 -- content/who/members.md --
358 ---title: members who
359 draft: true
360 ---
361 -- layouts/list.html --
362 {{ with .GetPage "members.md" }}
363 Members: {{ .Title }}
364 {{ else }}
365 NOT FOUND
366 {{ end }}
367 `
368
369 b := Test(t, files)
370
371 b.AssertFileContent("public/what/index.html", `Members: members what`)
372 b.AssertFileContent("public/where/index.html", `Members: members where`)
373 b.AssertFileContent("public/who/index.html", `NOT FOUND`)
374 }
375
376 func TestGetPageIssue11883(t *testing.T) {
377 files := `
378 -- hugo.toml --
379 -- p1/index.md --
380 ---
381 title: p1
382 ---
383 -- p1/p1.xyz --
384 xyz.
385 -- layouts/home.html --
386 Home. {{ with .Page.GetPage "p1.xyz" }}{{ else }}OK 1{{ end }} {{ with .Site.GetPage "p1.xyz" }}{{ else }}OK 2{{ end }}
387 `
388
389 b := Test(t, files)
390 b.AssertFileContent("public/index.html", "Home. OK 1 OK 2")
391 }
392
393 func TestGetPageIssue12120(t *testing.T) {
394 t.Parallel()
395
396 files := `
397 -- hugo.toml --
398 disableKinds = ['home','rss','section','sitemap','taxonomy','term']
399 -- content/s1/p1/index.md --
400 ---
401 title: p1
402 layout: p1
403 ---
404 -- content/s1/p2.md --
405 ---
406 title: p2
407 layout: p2
408 ---
409 -- layouts/p1.html --
410 {{ (.GetPage "p2.md").Title }}|
411 -- layouts/p2.html --
412 {{ (.GetPage "p1").Title }}|
413 `
414
415 b := Test(t, files)
416 b.AssertFileContent("public/s1/p1/index.html", "p2") // failing test
417 b.AssertFileContent("public/s1/p2/index.html", "p1")
418 }
419
420 func TestGetPageNewsVsTagsNewsIssue12638(t *testing.T) {
421 t.Parallel()
422
423 files := `
424 -- hugo.toml --
425 disableKinds = ['rss','section','sitemap']
426 [taxonomies]
427 tag = "tags"
428 -- content/p1.md --
429 ---
430 title: p1
431 tags: [news]
432 ---
433 -- layouts/home.html --
434 /tags/news: {{ with .Site.GetPage "/tags/news" }}{{ .Title }}{{ end }}|
435 news: {{ with .Site.GetPage "news" }}{{ .Title }}{{ end }}|
436 /news: {{ with .Site.GetPage "/news" }}{{ .Title }}{{ end }}|
437
438 `
439
440 b := Test(t, files)
441
442 b.AssertFileContent("public/index.html",
443 "/tags/news: News|",
444 "news: News|",
445 "/news: |",
446 )
447 }
448
449 func TestGetPageBundleToRegular(t *testing.T) {
450 files := `
451 -- hugo.toml --
452 -- content/s1/p1/index.md --
453 ---
454 title: p1
455 ---
456 -- content/s1/p2.md --
457 ---
458 title: p2
459 ---
460 -- layouts/single.html --
461 {{ with .GetPage "p2" }}
462 OK: {{ .LinkTitle }}
463 {{ else }}
464 Unable to get p2.
465 {{ end }}
466 `
467
468 b := Test(t, files)
469 b.AssertFileContent("public/s1/p1/index.html", "OK: p2")
470 b.AssertFileContent("public/s1/p2/index.html", "OK: p2")
471 }
472
473 func TestPageGetPageVariations(t *testing.T) {
474 files := `
475 -- hugo.toml --
476 -- content/s1/_index.md --
477 ---
478 title: s1 section
479 ---
480 -- content/s1/p1/index.md --
481 ---
482 title: p1
483 ---
484 -- content/s1/p2.md --
485 ---
486 title: p2
487 ---
488 -- content/s2/p3/index.md --
489 ---
490 title: p3
491 ---
492 -- content/p2.md --
493 ---
494 title: p2_root
495 ---
496 -- layouts/home.html --
497 /s1: {{ with .GetPage "/s1" }}{{ .Title }}{{ end }}|
498 /s1/: {{ with .GetPage "/s1/" }}{{ .Title }}{{ end }}|
499 /s1/p2.md: {{ with .GetPage "/s1/p2.md" }}{{ .Title }}{{ end }}|
500 /s1/p2: {{ with .GetPage "/s1/p2" }}{{ .Title }}{{ end }}|
501 /s1/p1/index.md: {{ with .GetPage "/s1/p1/index.md" }}{{ .Title }}{{ end }}|
502 /s1/p1: {{ with .GetPage "/s1/p1" }}{{ .Title }}{{ end }}|
503 -- layouts/single.html --
504 ../p2: {{ with .GetPage "../p2" }}{{ .Title }}{{ end }}|
505 ../p2.md: {{ with .GetPage "../p2.md" }}{{ .Title }}{{ end }}|
506 p1/index.md: {{ with .GetPage "p1/index.md" }}{{ .Title }}{{ end }}|
507 ../s2/p3/index.md: {{ with .GetPage "../s2/p3/index.md" }}{{ .Title }}{{ end }}|
508 `
509
510 b := Test(t, files)
511
512 b.AssertFileContent("public/index.html", `
513 /s1: s1 section|
514 /s1/: s1 section|
515 /s1/p2.md: p2|
516 /s1/p2: p2|
517 /s1/p1/index.md: p1|
518 /s1/p1: p1|
519 `)
520
521 b.AssertFileContent("public/s1/p1/index.html", `
522 ../p2: p2_root|
523 ../p2.md: p2|
524
525 `)
526
527 b.AssertFileContent("public/s1/p2/index.html", `
528 ../p2: p2_root|
529 ../p2.md: p2_root|
530 p1/index.md: p1|
531 ../s2/p3/index.md: p3|
532
533 `)
534 }
535
536 func TestPageGetPageMountsReverseLookup(t *testing.T) {
537 t.Parallel()
538
539 files := `
540 -- hugo.toml --
541 baseURL = "https://example.com/"
542 [module]
543 [[module.mounts]]
544 source = "layouts"
545 target = "layouts"
546 [[module.mounts]]
547 source = "README.md"
548 target = "content/_index.md"
549 [[module.mounts]]
550 source = "blog"
551 target = "content/posts"
552 [[module.mounts]]
553 source = "docs"
554 target = "content/mydocs"
555 -- README.md --
556 ---
557 title: README
558 ---
559 -- blog/b1.md --
560 ---
561 title: b1
562 ---
563 {{< ref "../docs/d1.md" >}}
564 -- blog/b2/index.md --
565 ---
566 title: b2
567 ---
568 {{< ref "../../docs/d1.md" >}}
569 -- docs/d1.md --
570 ---
571 title: d1
572 ---
573 -- layouts/_shortcodes/ref.html --
574 {{ $ref := .Get 0 }}
575 .Page.GetPage({{ $ref }}).Title: {{ with .Page.GetPage $ref }}{{ .Title }}{{ end }}|
576 -- layouts/home.html --
577 Home.
578 /blog/b1.md: {{ with .GetPage "/blog/b1.md" }}{{ .Title }}{{ end }}|
579 /blog/b2/index.md: {{ with .GetPage "/blog/b2/index.md" }}{{ .Title }}{{ end }}|
580 /docs/d1.md: {{ with .GetPage "/docs/d1.md" }}{{ .Title }}{{ end }}|
581 /README.md: {{ with .GetPage "/README.md" }}{{ .Title }}{{ end }}|
582 -- layouts/single.html --
583 Single.
584 /README.md: {{ with .GetPage "/README.md" }}{{ .Title }}{{ end }}|
585 {{ .Content }}
586 `
587 b := Test(t, files)
588
589 b.AssertFileContent("public/index.html",
590 `
591 /blog/b1.md: b1|
592 /blog/b2/index.md: b2|
593 /docs/d1.md: d1|
594 /README.md: README
595 `,
596 )
597
598 b.AssertFileContent("public/mydocs/d1/index.html", `README.md: README|`)
599
600 b.AssertFileContent("public/posts/b1/index.html", `.Page.GetPage(../docs/d1.md).Title: d1|`)
601 b.AssertFileContent("public/posts/b2/index.html", `.Page.GetPage(../../docs/d1.md).Title: d1|`)
602 }
603
604 // https://github.com/gohugoio/hugo/issues/7016
605 func TestGetPageMultilingual(t *testing.T) {
606 t.Parallel()
607
608 files := `
609 -- hugo.toml --
610 baseURL = "http://example.org/"
611 locale = "en-us"
612 defaultContentLanguage = "ru"
613 title = "My New Hugo Project"
614 uglyurls = true
615
616 [languages]
617 [languages.ru]
618 [languages.en]
619 -- content/docs/1.md --
620 ---
621 title: p1
622 ---
623 -- content/news/1.md --
624 ---
625 title: p1
626 ---
627 -- content/news/1.en.md --
628 ---
629 title: p1en
630 ---
631 -- content/news/about/1.md --
632 ---
633 title: about1
634 ---
635 -- content/news/about/1.en.md --
636 ---
637 title: about1en
638 ---
639 -- layouts/home.html --
640 {{ with site.GetPage "docs/1" }}
641 Docs p1: {{ .Title }}
642 {{ else }}
643 NOT FOUND
644 {{ end }}
645 `
646 b := Test(t, files)
647
648 b.AssertFileContent("public/index.html", `Docs p1: p1`)
649 b.AssertFileContent("public/en/index.html", `NOT FOUND`)
650 }
651
652 func TestRegularPagesRecursive(t *testing.T) {
653 t.Parallel()
654
655 files := `
656 -- hugo.toml --
657 baseURL = "http://example.org/"
658 title = "My New Hugo Project"
659 -- content/docs/1.md --
660 ---
661 title: docs1
662 ---
663 -- content/docs/sect1/_index.md --
664 ---
665 title: docs_sect1
666 ---
667 -- content/docs/sect1/ps1.md --
668 ---
669 title: docs_sect1_ps1
670 ---
671 -- content/docs/sect1/ps2.md --
672 ---
673 title: docs_sect1_ps2
674 ---
675 -- content/docs/sect1/sect1_s2/_index.md --
676 ---
677 title: docs_sect1_s2
678 ---
679 -- content/docs/sect1/sect1_s2/ps2_1.md --
680 ---
681 title: docs_sect1_s2_1
682 ---
683 -- content/docs/sect2/_index.md --
684 ---
685 title: docs_sect2
686 ---
687 -- content/docs/sect2/ps1.md --
688 ---
689 title: docs_sect2_ps1
690 ---
691 -- content/docs/sect2/ps2.md --
692 ---
693 title: docs_sect2_ps2
694 ---
695 -- content/news/1.md --
696 ---
697 title: news1
698 ---
699 -- layouts/home.html --
700 {{ $sect1 := site.GetPage "sect1" }}
701
702 Sect1 RegularPagesRecursive: {{ range $sect1.RegularPagesRecursive }}{{ .Kind }}:{{ .RelPermalink}}|{{ end }}|End.
703 `
704 b := Test(t, files)
705
706 b.AssertFileContent("public/index.html", `
707 Sect1 RegularPagesRecursive: page:/docs/sect1/ps1/|page:/docs/sect1/ps2/|page:/docs/sect1/sect1_s2/ps2_1/||End.
708
709
710 `)
711 }
712
713 func TestRegularPagesRecursiveHome(t *testing.T) {
714 files := `
715 -- hugo.toml --
716 -- content/p1.md --
717 -- content/post/p2.md --
718 -- layouts/home.html --
719 RegularPagesRecursive: {{ range .RegularPagesRecursive }}{{ .Kind }}:{{ .RelPermalink}}|{{ end }}|End.
720 `
721
722 b := Test(t, files)
723
724 b.AssertFileContent("public/index.html", `RegularPagesRecursive: page:/p1/|page:/post/p2/||End.`)
725 }
726
727 // Issue #12169.
728 func TestPagesSimilarSectionNames(t *testing.T) {
729 files := `
730 -- hugo.toml --
731 -- content/draftsection/_index.md --
732 ---
733 draft: true
734 ---
735 -- content/draftsection/sub/_index.md --got
736 -- content/draftsection/sub/d1.md --
737 -- content/s1/_index.md --
738 -- content/s1/p1.md --
739 -- content/s1-foo/_index.md --
740 -- content/s1-foo/p2.md --
741 -- content/s1-foo/s2/_index.md --
742 -- content/s1-foo/s2/p3.md --
743 -- content/s1-foo/s2-foo/_index.md --
744 -- content/s1-foo/s2-foo/p4.md --
745 -- layouts/list.html --
746 {{ .RelPermalink }}: Pages: {{ range .Pages }}{{ .RelPermalink }}|{{ end }}$
747
748 `
749 b := Test(t, files)
750
751 b.AssertFileContent("public/index.html", "/: Pages: /s1-foo/|/s1/|$")
752 b.AssertFileContent("public/s1/index.html", "/s1/: Pages: /s1/p1/|$")
753 b.AssertFileContent("public/s1-foo/index.html", "/s1-foo/: Pages: /s1-foo/p2/|/s1-foo/s2-foo/|/s1-foo/s2/|$")
754 b.AssertFileContent("public/s1-foo/s2/index.html", "/s1-foo/s2/: Pages: /s1-foo/s2/p3/|$")
755 }
756
757 func TestGetPageContentAdapterBaseIssue12561(t *testing.T) {
758 t.Parallel()
759
760 files := `
761 -- hugo.toml --
762 disableKinds = ['rss','section','sitemap','taxonomy','term']
763 -- layouts/home.html --
764 Test A: {{ (site.GetPage "/s1/p1").Title }}
765 Test B: {{ (site.GetPage "p1").Title }}
766 Test C: {{ (site.GetPage "/s2/p2").Title }}
767 Test D: {{ (site.GetPage "p2").Title }}
768 -- layouts/single.html --
769 {{ .Title }}
770 -- content/s1/p1.md --
771 ---
772 title: p1
773 ---
774 -- content/s2/_content.gotmpl --
775 {{ .AddPage (dict "path" "p2" "title" "p2") }}
776 `
777
778 b := Test(t, files)
779
780 b.AssertFileExists("public/s1/p1/index.html", true)
781 b.AssertFileExists("public/s2/p2/index.html", true)
782 b.AssertFileContent("public/index.html",
783 "Test A: p1",
784 "Test B: p1",
785 "Test C: p2",
786 "Test D: p2", // fails
787 )
788 }