From 87e100e61f53efeb307c70af01d6d304b6ea4f1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Fri, 15 Aug 2025 13:10:27 +0200 Subject: [PATCH] Fix rebuild when deleting a content adapter file --- hugolib/hugo_sites_build.go | 6 ++- hugolib/pages_capture.go | 4 ++ .../pagesfromgotmpl_integration_test.go | 39 +++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/hugolib/hugo_sites_build.go b/hugolib/hugo_sites_build.go index ce8ddd143..bad55a210 100644 --- a/hugolib/hugo_sites_build.go +++ b/hugolib/hugo_sites_build.go @@ -921,12 +921,14 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo if err == nil { f.Close() } + if err != nil { // Remove all pages and resources below. - prefix := pathInfo.Base() + "/" + prefix := paths.AddTrailingSlash(pathInfo.Base()) + h.pageTrees.treePages.DeletePrefixAll(prefix) h.pageTrees.resourceTrees.DeletePrefixAll(prefix) - changes = append(changes, identity.NewGlobIdentity(prefix+"*")) + changes = append(changes, identity.NewGlobIdentity(prefix+"**")) } return err != nil }) diff --git a/hugolib/pages_capture.go b/hugolib/pages_capture.go index 50900e585..37ed3c89c 100644 --- a/hugolib/pages_capture.go +++ b/hugolib/pages_capture.go @@ -192,6 +192,10 @@ func (c *pagesCollector) Collect() (collectErr error) { return strings.HasPrefix(fim.Meta().PathInfo.Path(), paths.AddTrailingSlash(id.p.Path())) } + if id.p.IsContentData() { + return strings.HasPrefix(fim.Meta().PathInfo.Path(), paths.AddTrailingSlash(id.p.Dir())) + } + return id.p.Dir() == fim.Meta().PathInfo.Dir() } diff --git a/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go b/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go index ffd0c5f5b..ae8b072c8 100644 --- a/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go +++ b/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go @@ -308,6 +308,45 @@ func TestPagesFromGoTmplRemoveGoTmpl(t *testing.T) { b.AssertFileContent("public/docs/index.html", "RegularPagesRecursive: pfile:/docs/pfile|$") } +func TestPagesFromGoTmplEditOverlappingContentFile(t *testing.T) { + t.Parallel() + files := ` +-- hugo.toml -- +disableLiveReload = true +disableKinds = ["taxonomy", "term", "rss", "sitemap"] +-- layouts/all.html -- +All: {{ .Content }}|{{ .Title }}| +-- layouts/section.html -- +Title: {{ .Title}}| +RegularPages: {{ range .RegularPages }}{{ .Title }}:{{ .Path }}|{{ end }}| +-- content/mysection/_index.md -- +--- +title: "My Section" +--- +-- content/mysection/p1.md -- +--- +title: "p1 content file" +--- +Content of p1 +-- content/_content.gotmpl -- +{{ $.AddPage (dict "kind" "page" "path" "mysection/p2" "title" "p2 content adapter") }} +` + b := hugolib.TestRunning(t, files) + b.AssertFileContent("public/mysection/index.html", "Title: My Section|", "RegularPages: p1 content file:/mysection/p1|p2 content adapter:/mysection/p2|") + + b.EditFileReplaceAll("content/mysection/p1.md", `"p1 content file"`, `"p1 content file edited"`).Build() + b.AssertFileContent("public/mysection/index.html", "RegularPages: p1 content file edited:/mysection/p1|p2 content adapter:/mysection/p2|") + + b.EditFileReplaceAll("content/mysection/_index.md", "My Section", "My Section edited").Build() + b.AssertFileContent("public/mysection/index.html", "Title: My Section edited|", "RegularPages: p1 content file edited:/mysection/p1|p2 content adapter:/mysection/p2|") + + b.RemoveFiles("content/mysection/p1.md").Build() + b.AssertFileContent("public/mysection/index.html", "Title: My Section edited|\nRegularPages: p2 content adapter:/mysection/p2|") + + b.RemoveFiles("content/_content.gotmpl", "public/mysection/index.html").Build() + b.AssertFileContent("public/mysection/index.html", "Title: My Section edited|\nRegularPages: |") +} + // Issue #13443. func TestPagesFromGoRelatedKeywords(t *testing.T) { t.Parallel()