diff --git a/hugolib/content_map.go b/hugolib/content_map.go index b75ccdbcb7d..23a584d3052 100644 --- a/hugolib/content_map.go +++ b/hugolib/content_map.go @@ -164,6 +164,24 @@ func (cfg contentMapConfig) getTaxonomyConfig(s string) (v viewName) { return } +func (m *pageMap) insertPage(s string, p *pageState) (contentNodeI, contentNodeI, bool) { + u, n, replaced := m.treePages.InsertIntoValuesDimensionWithLock(s, p) + + if replaced && !m.s.h.isRebuild() && m.s.conf.PrintPathWarnings { + var messageDetail string + if p1, ok := n.(*pageState); ok && p1.File() != nil { + messageDetail = fmt.Sprintf(" file: %q", p1.File().Filename()) + } + if p2, ok := u.(*pageState); ok && p2.File() != nil { + messageDetail += fmt.Sprintf(" file: %q", p2.File().Filename()) + } + + m.s.Log.Warnf("Duplicate content path: %q%s", s, messageDetail) + } + + return u, n, replaced +} + func (m *pageMap) AddFi(fi hugofs.FileMetaInfo, buildConfig *BuildCfg) (pageCount uint64, resourceCount uint64, addErr error) { if fi.IsDir() { return @@ -261,7 +279,7 @@ func (m *pageMap) AddFi(fi hugofs.FileMetaInfo, buildConfig *BuildCfg) (pageCoun return } - m.treePages.InsertIntoValuesDimensionWithLock(pi.Base(), p) + m.insertPage(pi.Base(), p) } return @@ -336,7 +354,7 @@ func (m *pageMap) addPagesFromGoTmplFi(fi hugofs.FileMetaInfo, buildConfig *Buil return nil } - u, n, replaced := s.pageMap.treePages.InsertIntoValuesDimensionWithLock(pi.Base(), ps) + u, n, replaced := s.pageMap.insertPage(pi.Base(), ps) if h.isRebuild() { if replaced { diff --git a/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go b/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go index 75283a1229c..cb5ca096ec1 100644 --- a/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go +++ b/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go @@ -518,3 +518,35 @@ disableKinds = ['home','section','rss','sitemap','taxonomy','term'] "data1.yaml|param1v", ) } + +func TestPagesFromGoTmplPathWarningsIssue12511(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") +}