Skip to content

Commit 87e100e

Browse files
committed
Fix rebuild when deleting a content adapter file
1 parent 1649f31 commit 87e100e

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

hugolib/hugo_sites_build.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -921,12 +921,14 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo
921921
if err == nil {
922922
f.Close()
923923
}
924+
924925
if err != nil {
925926
// Remove all pages and resources below.
926-
prefix := pathInfo.Base() + "/"
927+
prefix := paths.AddTrailingSlash(pathInfo.Base())
928+
927929
h.pageTrees.treePages.DeletePrefixAll(prefix)
928930
h.pageTrees.resourceTrees.DeletePrefixAll(prefix)
929-
changes = append(changes, identity.NewGlobIdentity(prefix+"*"))
931+
changes = append(changes, identity.NewGlobIdentity(prefix+"**"))
930932
}
931933
return err != nil
932934
})

hugolib/pages_capture.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ func (c *pagesCollector) Collect() (collectErr error) {
192192
return strings.HasPrefix(fim.Meta().PathInfo.Path(), paths.AddTrailingSlash(id.p.Path()))
193193
}
194194

195+
if id.p.IsContentData() {
196+
return strings.HasPrefix(fim.Meta().PathInfo.Path(), paths.AddTrailingSlash(id.p.Dir()))
197+
}
198+
195199
return id.p.Dir() == fim.Meta().PathInfo.Dir()
196200
}
197201

hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,45 @@ func TestPagesFromGoTmplRemoveGoTmpl(t *testing.T) {
308308
b.AssertFileContent("public/docs/index.html", "RegularPagesRecursive: pfile:/docs/pfile|$")
309309
}
310310

311+
func TestPagesFromGoTmplEditOverlappingContentFile(t *testing.T) {
312+
t.Parallel()
313+
files := `
314+
-- hugo.toml --
315+
disableLiveReload = true
316+
disableKinds = ["taxonomy", "term", "rss", "sitemap"]
317+
-- layouts/all.html --
318+
All: {{ .Content }}|{{ .Title }}|
319+
-- layouts/section.html --
320+
Title: {{ .Title}}|
321+
RegularPages: {{ range .RegularPages }}{{ .Title }}:{{ .Path }}|{{ end }}|
322+
-- content/mysection/_index.md --
323+
---
324+
title: "My Section"
325+
---
326+
-- content/mysection/p1.md --
327+
---
328+
title: "p1 content file"
329+
---
330+
Content of p1
331+
-- content/_content.gotmpl --
332+
{{ $.AddPage (dict "kind" "page" "path" "mysection/p2" "title" "p2 content adapter") }}
333+
`
334+
b := hugolib.TestRunning(t, files)
335+
b.AssertFileContent("public/mysection/index.html", "Title: My Section|", "RegularPages: p1 content file:/mysection/p1|p2 content adapter:/mysection/p2|")
336+
337+
b.EditFileReplaceAll("content/mysection/p1.md", `"p1 content file"`, `"p1 content file edited"`).Build()
338+
b.AssertFileContent("public/mysection/index.html", "RegularPages: p1 content file edited:/mysection/p1|p2 content adapter:/mysection/p2|")
339+
340+
b.EditFileReplaceAll("content/mysection/_index.md", "My Section", "My Section edited").Build()
341+
b.AssertFileContent("public/mysection/index.html", "Title: My Section edited|", "RegularPages: p1 content file edited:/mysection/p1|p2 content adapter:/mysection/p2|")
342+
343+
b.RemoveFiles("content/mysection/p1.md").Build()
344+
b.AssertFileContent("public/mysection/index.html", "Title: My Section edited|\nRegularPages: p2 content adapter:/mysection/p2|")
345+
346+
b.RemoveFiles("content/_content.gotmpl", "public/mysection/index.html").Build()
347+
b.AssertFileContent("public/mysection/index.html", "Title: My Section edited|\nRegularPages: |")
348+
}
349+
311350
// Issue #13443.
312351
func TestPagesFromGoRelatedKeywords(t *testing.T) {
313352
t.Parallel()

0 commit comments

Comments
 (0)