Debian Codegraph @

resources/page/permalinks_integration_test.go

raw
1 // Copyright 2024 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 page_test
15
16 import (
17 "fmt"
18 "strings"
19 "testing"
20
21 "github.com/bep/logg"
22 qt "github.com/frankban/quicktest"
23 "github.com/gohugoio/hugo/htesting"
24 "github.com/gohugoio/hugo/hugolib"
25 )
26
27 func TestPermalinks(t *testing.T) {
28 t.Parallel()
29
30 files := `
31 -- layouts/list.html --
32 List|{{ .Kind }}|{{ .RelPermalink }}|
33 -- layouts/single.html --
34 Single|{{ .Kind }}|{{ .RelPermalink }}|
35 -- hugo.toml --
36 [taxonomies]
37 tag = "tags"
38 [permalinks.page]
39 withpageslug = '/pageslug/:slug/'
40 withallbutlastsection = '/:sections[:last]/:slug/'
41 withallbutlastsectionslug = '/:sectionslugs[:last]/:slug/'
42 withsectionslug = '/sectionslug/:sectionslug/:slug/'
43 withsectionslugs = '/sectionslugs/:sectionslugs/:slug/'
44 [permalinks.section]
45 withfilefilename = '/sectionwithfilefilename/:contentbasename/'
46 withfilefiletitle = '/sectionwithfilefiletitle/:title/'
47 withfileslug = '/sectionwithfileslug/:slug/'
48 nofileslug = '/sectionnofileslug/:slug/'
49 nofilefilename = '/sectionnofilefilename/:contentbasename/'
50 nofiletitle1 = '/sectionnofiletitle1/:title/'
51 nofiletitle2 = '/sectionnofiletitle2/:sections[:last]/'
52 [permalinks.term]
53 tags = '/tagsslug/tag/:slug/'
54 [permalinks.taxonomy]
55 tags = '/tagsslug/:slug/'
56 -- content/withpageslug/p1.md --
57 ---
58 slug: "p1slugvalue"
59 tags: ["mytag"]
60 ---
61 -- content/withfilefilename/_index.md --
62 -- content/withfileslug/_index.md --
63 ---
64 slug: "withfileslugvalue"
65 ---
66 -- content/nofileslug/p1.md --
67 -- content/nofilefilename/p1.md --
68 -- content/nofiletitle1/p1.md --
69 -- content/nofiletitle2/asdf/p1.md --
70 -- content/withallbutlastsection/subsection/p1.md --
71 -- content/withallbutlastsectionslug/_index.md --
72 ---
73 slug: "root-section-slug"
74 ---
75 -- content/withallbutlastsectionslug/subsection/_index.md --
76 ---
77 slug: "sub-section-slug"
78 ---
79 -- content/withallbutlastsectionslug/subsection/p1.md --
80 ---
81 slug: "page-slug"
82 ---
83 -- content/withsectionslug/_index.md --
84 ---
85 slug: "section-root-slug"
86 ---
87 -- content/withsectionslug/subsection/_index.md --
88 -- content/withsectionslug/subsection/p1.md --
89 ---
90 slug: "page1-slug"
91 ---
92 -- content/withsectionslugs/_index.md --
93 ---
94 slug: "sections-root-slug"
95 ---
96 -- content/withsectionslugs/level1/_index.md --
97 ---
98 slug: "level1-slug"
99 ---
100 -- content/withsectionslugs/level1/p1.md --
101 ---
102 slug: "page1-slug"
103 ---
104 -- content/tags/_index.md --
105 ---
106 slug: "tagsslug"
107 ---
108 -- content/tags/mytag/_index.md --
109 ---
110 slug: "mytagslug"
111 ---
112
113
114 `
115
116 b := hugolib.Test(t, files, hugolib.TestOptWarn())
117
118 t.Log(b.LogString())
119 // No .File.TranslationBaseName on zero object etc. warnings.
120 b.Assert(b.H.Log.LoggCount(logg.LevelWarn), qt.Equals, 0)
121 b.AssertFileContent("public/pageslug/p1slugvalue/index.html", "Single|page|/pageslug/p1slugvalue/|")
122 b.AssertFileContent("public/sectionslug/section-root-slug/page1-slug/index.html", "Single|page|/sectionslug/section-root-slug/page1-slug/|")
123 b.AssertFileContent("public/sectionslugs/sections-root-slug/level1-slug/page1-slug/index.html", "Single|page|/sectionslugs/sections-root-slug/level1-slug/page1-slug/|")
124
125 b.AssertFileContent("public/sectionwithfilefilename/withfilefilename/index.html", "List|section|/sectionwithfilefilename/withfilefilename/|")
126
127 b.AssertFileContent("public/sectionwithfileslug/withfileslugvalue/index.html", "List|section|/sectionwithfileslug/withfileslugvalue/|")
128
129 b.AssertFileContent("public/sectionnofilefilename/nofilefilename/index.html", "List|section|/sectionnofilefilename/nofilefilename/|")
130 b.AssertFileContent("public/sectionnofileslug/nofileslugs/index.html", "List|section|/sectionnofileslug/nofileslugs/|")
131 b.AssertFileContent("public/sectionnofiletitle1/nofiletitle1s/index.html", "List|section|/sectionnofiletitle1/nofiletitle1s/|")
132 b.AssertFileContent("public/sectionnofiletitle2/index.html", "List|section|/sectionnofiletitle2/|")
133
134 b.AssertFileContent("public/tagsslug/tag/mytagslug/index.html", "List|term|/tagsslug/tag/mytagslug/|")
135 b.AssertFileContent("public/tagsslug/tagsslug/index.html", "List|taxonomy|/tagsslug/tagsslug/|")
136
137 permalinksConf := b.H.Configs.Base.Permalinks
138 // 5 page + 7 section + 1 taxonomy + 1 term = 14 rules.
139 b.Assert(len(permalinksConf), qt.Equals, 14)
140 }
141
142 func TestPermalinksOldSetup(t *testing.T) {
143 t.Parallel()
144
145 files := `
146 -- layouts/list.html --
147 List|{{ .Kind }}|{{ .RelPermalink }}|
148 -- layouts/single.html --
149 Single|{{ .Kind }}|{{ .RelPermalink }}|
150 -- hugo.toml --
151 [permalinks]
152 withpageslug = '/pageslug/:slug/'
153 -- content/withpageslug/p1.md --
154 ---
155 slug: "p1slugvalue"
156 ---
157
158
159
160
161 `
162
163 b := hugolib.Test(t, files, hugolib.TestOptWarn())
164
165 t.Log(b.LogString())
166 // No .File.TranslationBaseName on zero object etc. warnings.
167 b.Assert(b.H.Log.LoggCount(logg.LevelWarn), qt.Equals, 0)
168 b.AssertFileContent("public/pageslug/p1slugvalue/index.html", "Single|page|/pageslug/p1slugvalue/|")
169
170 permalinksConf := b.H.Configs.Base.Permalinks
171 // Old flat format: 1 entry creates 2 rules (page + term).
172 b.Assert(len(permalinksConf), qt.Equals, 2)
173 }
174
175 func TestPermalinksNestedSections(t *testing.T) {
176 t.Parallel()
177
178 files := `
179 -- hugo.toml --
180 [permalinks.page]
181 books = '/libros/:sections[1:]/:contentbasename'
182
183 [permalinks.section]
184 books = '/libros/:sections[1:]'
185 -- content/books/_index.md --
186 ---
187 title: Books
188 ---
189 -- content/books/fiction/_index.md --
190 ---
191 title: Fiction
192 ---
193 -- content/books/fiction/2023/_index.md --
194 ---
195 title: 2023
196 ---
197 -- content/books/fiction/2023/book1/index.md --
198 ---
199 title: Book 1
200 ---
201 -- layouts/single.html --
202 Single.
203 -- layouts/list.html --
204 List.
205 `
206
207 b := hugolib.Test(t, files, hugolib.TestOptWarn())
208
209 t.Log(b.LogString())
210 // No .File.TranslationBaseName on zero object etc. warnings.
211 b.Assert(b.H.Log.LoggCount(logg.LevelWarn), qt.Equals, 0)
212
213 b.AssertFileContent("public/libros/index.html", "List.")
214 b.AssertFileContent("public/libros/fiction/index.html", "List.")
215 b.AssertFileContent("public/libros/fiction/2023/book1/index.html", "Single.")
216 }
217
218 func TestPermalinksNestedSectionsWithSlugs(t *testing.T) {
219 t.Parallel()
220
221 files := `
222 -- hugo.toml --
223 [permalinks.page]
224 books = '/libros/:sectionslugs[1:]/:slug'
225
226 [permalinks.section]
227 books = '/libros/:sectionslugs[1:]'
228 -- content/books/_index.md --
229 ---
230 title: Books
231 ---
232 -- content/books/fiction/_index.md --
233 ---
234 title: Fiction
235 slug: fictionslug
236 ---
237 -- content/books/fiction/2023/_index.md --
238 ---
239 title: 2023
240 ---
241 -- content/books/fiction/2023/book1/index.md --
242 ---
243 title: Book One
244 ---
245 -- layouts/single.html --
246 Single.
247 -- layouts/list.html --
248 List.
249 `
250
251 b := hugolib.Test(t, files, hugolib.TestOptWarn())
252
253 t.Log(b.LogString())
254 // No .File.TranslationBaseName on zero object etc. warnings.
255 b.Assert(b.H.Log.LoggCount(logg.LevelWarn), qt.Equals, 0)
256
257 b.AssertFileContent("public/libros/index.html", "List.")
258 b.AssertFileContent("public/libros/fictionslug/index.html", "List.")
259 b.AssertFileContent("public/libros/fictionslug/2023/book-one/index.html", "Single.")
260 }
261
262 func TestPermalinksUrlCascade(t *testing.T) {
263 t.Parallel()
264
265 files := `
266 -- layouts/list.html --
267 List|{{ .Kind }}|{{ .RelPermalink }}|
268 -- layouts/single.html --
269 Single|{{ .Kind }}|{{ .RelPermalink }}|
270 -- hugo.toml --
271 -- content/cooking/delicious-recipes/_index.md --
272 ---
273 url: /delicious-recipe/
274 cascade:
275 url: /delicious-recipe/:slug/
276 ---
277 -- content/cooking/delicious-recipes/example1.md --
278 ---
279 title: Recipe 1
280 ---
281 -- content/cooking/delicious-recipes/example2.md --
282 ---
283 title: Recipe 2
284 slug: custom-recipe-2
285 ---
286 `
287 b := hugolib.Test(t, files, hugolib.TestOptWarn())
288
289 t.Log(b.LogString())
290 b.Assert(b.H.Log.LoggCount(logg.LevelWarn), qt.Equals, 0)
291 b.AssertFileContent("public/delicious-recipe/index.html", "List|section|/delicious-recipe/")
292 b.AssertFileContent("public/delicious-recipe/recipe-1/index.html", "Single|page|/delicious-recipe/recipe-1/")
293 b.AssertFileContent("public/delicious-recipe/custom-recipe-2/index.html", "Single|page|/delicious-recipe/custom-recipe-2/")
294 }
295
296 // Issue 12948.
297 // Issue 12954.
298 func TestPermalinksWithEscapedColons(t *testing.T) {
299 t.Parallel()
300
301 if htesting.IsWindows() {
302 t.Skip("Windows does not support colons in paths")
303 }
304
305 files := `
306 -- hugo.toml --
307 disableKinds = ['home','rss','sitemap','taxonomy','term']
308 [permalinks.page]
309 s2 = "/c\\:d/:slug/"
310 -- content/s1/_index.md --
311 ---
312 title: s1
313 url: "/a\\:b/:slug/"
314 ---
315 -- content/s1/p1.md --
316 ---
317 title: p1
318 url: "/a\\:b/:slug/"
319 ---
320 -- content/s2/p2.md --
321 ---
322 title: p2
323 ---
324 -- layouts/single.html --
325 {{ .Title }}
326 -- layouts/list.html --
327 {{ .Title }}
328 `
329
330 b := hugolib.Test(t, files)
331
332 b.AssertFileExists("public/a:b/p1/index.html", true)
333 b.AssertFileExists("public/a:b/s1/index.html", true)
334
335 // The above URLs come from the URL front matter field where everything is allowed.
336 // We strip colons from paths constructed by Hugo (they are not supported on Windows).
337 b.AssertFileExists("public/cd/p2/index.html", true)
338 }
339
340 func TestPermalinksContentbasenameContentAdapter(t *testing.T) {
341 t.Parallel()
342
343 files := `
344 -- hugo.toml --
345 [permalinks]
346 [permalinks.page]
347 a = "/:slugorcontentbasename/"
348 b = "/:sections/:contentbasename/"
349 -- content/_content.gotmpl --
350 {{ $.AddPage (dict "kind" "page" "path" "a/b/contentbasename1" "title" "My A Page No Slug") }}
351 {{ $.AddPage (dict "kind" "page" "path" "a/b/contentbasename2" "slug" "myslug" "title" "My A Page With Slug") }}
352 {{ $.AddPage (dict "kind" "section" "path" "b/c" "title" "My B Section") }}
353 {{ $.AddPage (dict "kind" "page" "path" "b/c/contentbasename3" "title" "My B Page No Slug") }}
354 -- layouts/single.html --
355 {{ .Title }}|{{ .RelPermalink }}|{{ .Kind }}|
356 `
357 b := hugolib.Test(t, files)
358
359 b.AssertFileContent("public/contentbasename1/index.html", "My A Page No Slug|/contentbasename1/|page|")
360 b.AssertFileContent("public/myslug/index.html", "My A Page With Slug|/myslug/|page|")
361 }
362
363 func TestPermalinksContentbasenameWithAndWithoutFile(t *testing.T) {
364 t.Parallel()
365
366 files := `
367 -- hugo.toml --
368 [permalinks.section]
369 a = "/mya/:contentbasename/"
370 [permalinks.page]
371 a = "/myapage/:contentbasename/"
372 [permalinks.term]
373 categories = "/myc/:slugorcontentbasename/"
374 -- content/b/c/_index.md --
375 ---
376 title: "C section"
377 ---
378 -- content/a/b/index.md --
379 ---
380 title: "My Title"
381 categories: ["c1", "c2"]
382 ---
383 -- content/categories/c2/_index.md --
384 ---
385 title: "C2"
386 slug: "c2slug"
387 ---
388 -- layouts/single.html --
389 {{ .Title }}|{{ .RelPermalink }}|{{ .Kind }}|
390 -- layouts/list.html --
391 {{ .Title }}|{{ .RelPermalink }}|{{ .Kind }}|
392 `
393 b := hugolib.Test(t, files)
394
395 // Sections.
396 b.AssertFileContent("public/mya/a/index.html", "As|/mya/a/|section|")
397
398 // Pages.
399 b.AssertFileContent("public/myapage/b/index.html", "My Title|/myapage/b/|page|")
400
401 // Taxonomies.
402 b.AssertFileContent("public/myc/c1/index.html", "C1|/myc/c1/|term|")
403 b.AssertFileContent("public/myc/c2slug/index.html", "C2|/myc/c2slug/|term|")
404 }
405
406 func TestIssue13755(t *testing.T) {
407 t.Parallel()
408
409 files := `
410 -- hugo.toml --
411 disableKinds = ['home','rss','section','sitemap','taxonomy','term']
412 disablePathToLower = false
413 [permalinks.page]
414 s1 = "/:contentbasename"
415 -- content/s1/aBc.md --
416 ---
417 title: aBc
418 ---
419 -- layouts/all.html --
420 {{ .Title }}
421 `
422
423 b := hugolib.Test(t, files)
424 b.AssertFileExists("public/abc/index.html", true)
425
426 files = strings.ReplaceAll(files, "disablePathToLower = false", "disablePathToLower = true")
427
428 b = hugolib.Test(t, files)
429 b.AssertFileExists("public/aBc/index.html", true)
430 }
431
432 func TestPermalinksTaxonomyAndPageConsistencyIssue14325(t *testing.T) {
433 t.Parallel()
434
435 filesTemplate := `
436 -- hugo.toml --
437 disableKinds = ['rss','sitemap']
438 %s
439 -- content/s1/p1.md --
440 ---
441 title: p1
442 date: 2026-04-02
443 tags: ['tag-a']
444 categories: ['category-a']
445 ---
446 %s
447 -- layouts/all.html --
448 {{ .Title }}|
449 `
450
451 tests := []struct {
452 explicitTermContent bool
453 kindSpecificConfig bool
454 }{
455 {true, true},
456 {false, true},
457 {true, false},
458 {false, false},
459 }
460
461 for _, tt := range tests {
462 name := fmt.Sprintf("explicitTermContent=%t/kindSpecificConfig=%t", tt.explicitTermContent, tt.kindSpecificConfig)
463
464 t.Run(name, func(t *testing.T) {
465 var permalinkConfig, termContent string
466
467 if tt.kindSpecificConfig {
468 permalinkConfig = `
469 [permalinks.page]
470 s1 = '/:year/:month/:day/:contentbasename/'
471 [permalinks.term]
472 categories = '/:contentbasename/'
473 tags = '/tags/:contentbasename/'`
474 } else {
475 permalinkConfig = `
476 [permalinks]
477 s1 = '/:year/:month/:day/:contentbasename/'
478 categories = '/:contentbasename/'
479 tags = '/tags/:contentbasename/'`
480 }
481
482 if tt.explicitTermContent {
483 termContent = `
484 -- content/categories/category-a/_index.md --
485 ---
486 title: Category A (set in front matter)
487 ---
488 -- content/tags/tag-a/_index.md --
489 ---
490 title: Tag A (set in front matter)
491 ---`
492 }
493
494 f := fmt.Sprintf(filesTemplate, permalinkConfig, termContent)
495 b := hugolib.Test(t, f)
496
497 b.AssertFileExists("public/2026/04/02/p1/index.html", true)
498 b.AssertFileExists("public/categories/index.html", true)
499 b.AssertFileExists("public/category-a/index.html", true)
500 b.AssertFileExists("public/index.html", true)
501 b.AssertFileExists("public/s1/index.html", true)
502 b.AssertFileExists("public/tags/index.html", true)
503 b.AssertFileExists("public/tags/tag-a/index.html", true)
504
505 b.AssertFileExists("public/categories/category-a/index.html", false)
506 b.AssertFileExists("public/s1/p1/index.html", false)
507 })
508 }
509 }
510
511 func TestPermalinksNewSliceFormat(t *testing.T) {
512 t.Parallel()
513
514 files := `
515 -- layouts/list.html --
516 List|{{ .Kind }}|{{ .RelPermalink }}|
517 -- layouts/single.html --
518 Single|{{ .Kind }}|{{ .RelPermalink }}|
519 -- hugo.yaml --
520 permalinks:
521 - target:
522 kind: page
523 path: "/books/**"
524 pattern: /books/:year/:slug/
525 - target:
526 kind: section
527 path: "/{books,books/**}"
528 pattern: /libros/:sections[1:]
529 - target:
530 kind: page
531 pattern: /other/:slug/
532 -- content/books/_index.md --
533 ---
534 title: Books
535 ---
536 -- content/books/fiction/_index.md --
537 ---
538 title: Fiction
539 ---
540 -- content/books/fiction/book1.md --
541 ---
542 title: Book One
543 date: 2023-06-15
544 slug: book-one
545 ---
546 -- content/other/p1.md --
547 ---
548 title: Other Page
549 slug: other-page
550 ---
551 -- content/unmatched/p2.md --
552 ---
553 title: Unmatched Page
554 slug: unmatched-page
555 ---
556 `
557
558 b := hugolib.Test(t, files)
559
560 // Page in /books section gets the books-specific pattern.
561 b.AssertFileContent("public/books/2023/book-one/index.html", "Single|page|/books/2023/book-one/|")
562 // Section page for books/fiction gets the section pattern.
563 b.AssertFileContent("public/libros/fiction/index.html", "List|section|/libros/fiction/|")
564 // Page outside /books matches the default page pattern.
565 b.AssertFileContent("public/other/other-page/index.html", "Single|page|/other/other-page/|")
566 // Page in unmatched section also matches the default page pattern.
567 b.AssertFileContent("public/other/unmatched-page/index.html", "Single|page|/other/unmatched-page/|")
568 }
569
570 func TestPermalinksNewSliceFormatEnvironment(t *testing.T) {
571 t.Parallel()
572
573 files := `
574 -- layouts/list.html --
575 List|{{ .Kind }}|{{ .RelPermalink }}|
576 -- layouts/single.html --
577 Single|{{ .Kind }}|{{ .RelPermalink }}|
578 -- hugo.toml --
579 disableKinds = ['home','rss','sitemap','taxonomy','term']
580 [[permalinks]]
581 pattern = "/testing/:slug/"
582 [permalinks.target]
583 path = "/books/**"
584 environment = "test"
585 [[permalinks]]
586 pattern = "/prod/:slug/"
587 [permalinks.target]
588 path = "/books/**"
589 environment = "production"
590 -- content/books/fiction/book1.md --
591 ---
592 title: Book One
593 date: 2023-06-15
594 slug: book-one
595 ---
596
597 `
598
599 b := hugolib.Test(t, files)
600
601 b.AssertPublishDir("prod", "! testing")
602 }
603
604 func TestPermalinksNewSliceFormatSitesMatrix(t *testing.T) {
605 t.Parallel()
606
607 files := `
608 -- layouts/single.html --
609 Single|{{ .Kind }}|{{ .RelPermalink }}|{{ .Language.Lang }}|
610 -- hugo.yaml --
611 defaultContentLanguage: en
612 defaultContentLanguageInSubdir: true
613 disableKinds: ['home','rss','section','sitemap','taxonomy','term']
614 languages:
615 en:
616 weight: 1
617 de:
618 weight: 2
619 permalinks:
620 - target:
621 kind: page
622 sites:
623 matrix:
624 languages: ["en"]
625 pattern: /en-posts/:slug/
626 - target:
627 kind: page
628 sites:
629 matrix:
630 languages: ["de"]
631 pattern: /de-posts/:slug/
632 - target:
633 kind: page
634 pattern: /other/:slug/
635 -- content/p1.en.md --
636 ---
637 title: Hello
638 slug: hello
639 ---
640 -- content/p1.de.md --
641 ---
642 title: Hallo
643 slug: hallo
644 ---
645 `
646
647 b := hugolib.Test(t, files)
648
649 // English page matches the en-specific rule.
650 b.AssertFileContent("public/en/en-posts/hello/index.html", "Single|page|/en/en-posts/hello/|en|")
651 // German page matches the de-specific rule.
652 b.AssertFileContent("public/de/de-posts/hallo/index.html", "Single|page|/de/de-posts/hallo/|de|")
653 }
654
655 // We only apply permalink patterns to kinds of type hone, page, section, taxonomy and term.
656 func TestPermalinksNewSliceFormatAsteriskKind(t *testing.T) {
657 t.Parallel()
658
659 files := `
660 -- hugo.toml --
661 enableRobotsTXT = true
662 [[permalinks]]
663 pattern = "/mylink/:slug/"
664 [permalinks.target]
665 kind = "*"
666 -- content/mysection/p1.md --
667 ---
668 title: My Page
669 slug: my-page
670 ---
671 -- layouts/all.html --
672 {{ .Title }}|{{ .RelPermalink }}|{{ .Kind }}|
673 -- layouts/404.html --
674 404.
675 `
676
677 b := hugolib.Test(t, files)
678 b.AssertPublishDir(`
679 404.html
680 index.html
681 index.xml
682 mylink/categories/index.html
683 mylink/my-page/index.html
684 mylink/mysections/index.html
685 mylink/tags/index.html
686 sitemap.xml
687 `)
688 }
689
690 func TestPermalinksHomeKind(t *testing.T) {
691 t.Parallel()
692
693 files := `
694 -- layouts/home.html --
695 Home|{{ .Kind }}|{{ .RelPermalink }}|
696 -- layouts/list.html --
697 List|{{ .Kind }}|{{ .RelPermalink }}|
698 -- hugo.yaml --
699 disableKinds: ['rss','sitemap','taxonomy','term']
700 permalinks:
701 - target:
702 kind: home
703 pattern: /welcome/
704 - target:
705 kind: section
706 pattern: /s/:slug/
707 -- content/mysection/_index.md --
708 ---
709 title: My Section
710 slug: my-section
711 ---
712 `
713
714 b := hugolib.Test(t, files, hugolib.TestOptWarn())
715 t.Log(b.LogString())
716 b.Assert(b.H.Log.LoggCount(logg.LevelWarn), qt.Equals, 0)
717 b.AssertFileContent("public/welcome/index.html", "Home|home|/welcome/|")
718 b.AssertFileContent("public/s/my-section/index.html", "List|section|/s/my-section/|")
719 }
720
721 func TestPermalinksHomeKindLegacyMap(t *testing.T) {
722 t.Parallel()
723
724 files := `
725 -- layouts/home.html --
726 Home|{{ .Kind }}|{{ .RelPermalink }}|
727 -- hugo.toml --
728 disableKinds = ['rss','sitemap','taxonomy','term']
729 [permalinks.home]
730 "/" = '/welcome/'
731 `
732
733 b := hugolib.Test(t, files, hugolib.TestOptWarn())
734 t.Log(b.LogString())
735 b.Assert(b.H.Log.LoggCount(logg.LevelWarn), qt.Equals, 0)
736 b.AssertFileContent("public/welcome/index.html", "Home|home|/welcome/|")
737 }
738
739 func TestPermalinksNewSliceFormatRootSection(t *testing.T) {
740 t.Parallel()
741
742 files := `
743 -- layouts/single.html --
744 Single|{{ .Kind }}|{{ .RelPermalink }}|
745 -- hugo.yaml --
746 permalinks:
747 - target:
748 kind: page
749 path: "/*"
750 pattern: /root/:slug/
751 - target:
752 kind: page
753 pattern: /deep/:slug/
754 -- content/p1.md --
755 ---
756 title: Root Page
757 slug: root-page
758 ---
759 -- content/sub/p2.md --
760 ---
761 title: Sub Page
762 slug: sub-page
763 ---
764 `
765
766 b := hugolib.Test(t, files)
767
768 // Root section page matches /* (non-recursive).
769 b.AssertFileContent("public/root/root-page/index.html", "Single|page|/root/root-page/|")
770 // Nested page matches the default rule.
771 b.AssertFileContent("public/deep/sub-page/index.html", "Single|page|/deep/sub-page/|")
772 }