aboutsummaryrefslogtreecommitdiffhomepage
path: root/hugolib/pagesfromdata
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2024-05-17 10:30:54 +0200
committerBjørn Erik Pedersen <[email protected]>2024-05-17 21:55:05 +0200
commit6b006616e5423c0906f2bfc52e103261fdfb04ef (patch)
tree1cae614339fd2822809e7098c035574fd285d840 /hugolib/pagesfromdata
parent3d40aba512931031921463dafc172c0d124437b8 (diff)
downloadhugo-6b006616e5423c0906f2bfc52e103261fdfb04ef.tar.gz
hugo-6b006616e5423c0906f2bfc52e103261fdfb04ef.zip
Also warn about duplicate content paths with --printPathWarnings
Closes #12511
Diffstat (limited to 'hugolib/pagesfromdata')
-rw-r--r--hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go67
1 files changed, 67 insertions, 0 deletions
diff --git a/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go b/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go
index 75283a122..7f0f19f1c 100644
--- a/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go
+++ b/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go
@@ -518,3 +518,70 @@ disableKinds = ['home','section','rss','sitemap','taxonomy','term']
"data1.yaml|param1v",
)
}
+
+func TestPagesFromGoTmplPathWarningsPathPage(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- hugo.toml --
+baseURL = "https://example.com"
+disableKinds = ['home','section','rss','sitemap','taxonomy','term']
+printPathWarnings = true
+-- content/_content.gotmpl --
+{{ .AddPage (dict "path" "p1" "title" "p1" ) }}
+{{ .AddPage (dict "path" "p2" "title" "p2" ) }}
+-- content/p1.md --
+---
+title: "p1"
+---
+-- layouts/_default/single.html --
+{{ .Title }}|
+`
+
+ b := hugolib.Test(t, files, hugolib.TestOptWarn())
+
+ b.AssertFileContent("public/p1/index.html", "p1|")
+
+ b.AssertLogContains("Duplicate content path")
+
+ files = strings.ReplaceAll(files, `"path" "p1"`, `"path" "p1new"`)
+
+ b = hugolib.Test(t, files, hugolib.TestOptWarn())
+
+ b.AssertLogNotContains("WARN")
+}
+
+func TestPagesFromGoTmplPathWarningsPathResource(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- hugo.toml --
+baseURL = "https://example.com"
+disableKinds = ['home','section','rss','sitemap','taxonomy','term']
+printPathWarnings = true
+-- content/_content.gotmpl --
+{{ .AddResource (dict "path" "p1/data1.yaml" "content" (dict "value" "data1" ) ) }}
+{{ .AddResource (dict "path" "p1/data2.yaml" "content" (dict "value" "data2" ) ) }}
+
+-- content/p1/index.md --
+---
+title: "p1"
+---
+-- content/p1/data1.yaml --
+value: data1
+-- layouts/_default/single.html --
+{{ .Title }}|
+`
+
+ b := hugolib.Test(t, files, hugolib.TestOptWarn())
+
+ b.AssertFileContent("public/p1/index.html", "p1|")
+
+ b.AssertLogContains("Duplicate resource path")
+
+ files = strings.ReplaceAll(files, `"path" "p1/data1.yaml"`, `"path" "p1/data1new.yaml"`)
+
+ b = hugolib.Test(t, files, hugolib.TestOptWarn())
+
+ b.AssertLogNotContains("WARN")
+}