]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Fix rebuild when deleting a content adapter file
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 15 Aug 2025 11:10:27 +0000 (13:10 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 15 Aug 2025 15:32:42 +0000 (17:32 +0200)
hugolib/hugo_sites_build.go
hugolib/pages_capture.go
hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go

index ce8ddd14365edcb541a1d4b2eec226173d0bf72a..bad55a210b69dbf9333e6b40adb03cd8466d54ec 100644 (file)
@@ -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
                                        })
index 50900e5853c87e9a13b2aafdd30d2521a0bffa23..37ed3c89ca0e90c932299a9a028ae8e11fd85f75 100644 (file)
@@ -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()
                                        }
 
index ffd0c5f5bf3efab5f425204ba51a5a4a04ac5f8b..ae8b072c8bdaf49f774afef53a1cf37635924ac7 100644 (file)
@@ -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()