Fix rebuild of changed bundled content files

Fixes #12000
This commit is contained in:
Bjørn Erik Pedersen 2024-02-06 20:26:18 +01:00
parent 146aedd7aa
commit a65622a13e
5 changed files with 37 additions and 7 deletions

View file

@ -480,6 +480,11 @@ func (p *Path) IsLeafBundle() bool {
return p.bundleType == PathTypeLeaf
}
func (p Path) ForBundleType(t PathType) *Path {
p.bundleType = t
return &p
}
func (p *Path) identifierAsString(i int) string {
i = p.identifierIndex(i)
if i == -1 {

View file

@ -127,7 +127,22 @@ type pageTrees struct {
// collectIdentities collects all identities from in all trees matching the given key.
// This will at most match in one tree, but may give identies from multiple dimensions (e.g. language).
func (t *pageTrees) collectIdentities(key string) []identity.Identity {
func (t *pageTrees) collectIdentities(p *paths.Path) []identity.Identity {
ids := t.collectIdentitiesFor(p.Base())
if p.Component() == files.ComponentFolderContent {
// It may also be a bundled content resource.
if n := t.treeResources.Get(p.ForBundleType(paths.PathTypeContentResource).Base()); n != nil {
n.ForEeachIdentity(func(id identity.Identity) bool {
ids = append(ids, id)
return false
})
}
}
return ids
}
func (t *pageTrees) collectIdentitiesFor(key string) []identity.Identity {
var ids []identity.Identity
if n := t.treePages.Get(key); n != nil {
n.ForEeachIdentity(func(id identity.Identity) bool {
@ -135,6 +150,7 @@ func (t *pageTrees) collectIdentities(key string) []identity.Identity {
return false
})
}
if n := t.treeResources.Get(key); n != nil {
n.ForEeachIdentity(func(id identity.Identity) bool {
ids = append(ids, id)

View file

@ -702,9 +702,7 @@ func (h *HugoSites) processPartial(ctx context.Context, l logg.LevelLogger, conf
switch pathInfo.Component() {
case files.ComponentFolderContent:
logger.Println("Source changed", pathInfo.Path())
base := pathInfo.Base()
if ids := h.pageTrees.collectIdentities(base); len(ids) > 0 {
if ids := h.pageTrees.collectIdentities(pathInfo); len(ids) > 0 {
changes = append(changes, ids...)
}
@ -723,7 +721,6 @@ func (h *HugoSites) processPartial(ctx context.Context, l logg.LevelLogger, conf
h.pageTrees.treeTaxonomyEntries.DeletePrefix("")
if delete {
_, ok := h.pageTrees.treePages.LongestPrefixAll(pathInfo.Base())
if ok {
h.pageTrees.treePages.DeleteAll(pathInfo.Base())

View file

@ -196,6 +196,11 @@ func (c *pagesCollector) Collect() (collectErr error) {
return id.p.Dir() == fim.Meta().PathInfo.Dir()
}
if fim.Meta().PathInfo.IsLeafBundle() && id.p.BundleType() == paths.PathTypeContentSingle {
return id.p.Dir() == fim.Meta().PathInfo.Dir()
}
return id.p.Path() == fim.Meta().PathInfo.Path()
})
}

View file

@ -39,7 +39,7 @@ My Section Bundle Text 2 Content.
---
title: "My Section Bundle Content"
---
My Section Bundle Content.
My Section Bundle Content Content.
-- content/mysection/_index.md --
---
title: "My Section"
@ -68,7 +68,7 @@ Foo.
func TestRebuildEditTextFileInLeafBundle(t *testing.T) {
b := TestRunning(t, rebuildFilesSimple)
b.AssertFileContent("public/mysection/mysectionbundle/index.html",
"Resources: 0:/mysection/mysectionbundle/mysectionbundletext.txt|My Section Bundle Text 2 Content.|1:|<p>My Section Bundle Content.</p>\n|$")
"Resources: 0:/mysection/mysectionbundle/mysectionbundletext.txt|My Section Bundle Text 2 Content.|1:|<p>My Section Bundle Content Content.</p>\n|$")
b.EditFileReplaceAll("content/mysection/mysectionbundle/mysectionbundletext.txt", "Content.", "Content Edited.").Build()
b.AssertFileContent("public/mysection/mysectionbundle/index.html",
@ -109,6 +109,13 @@ func TestRebuildRenameTextFileInLeafBundle(t *testing.T) {
b.AssertRenderCountContent(3)
}
func TestRebuilEditContentFileInLeafBundle(t *testing.T) {
b := TestRunning(t, rebuildFilesSimple)
b.AssertFileContent("public/mysection/mysectionbundle/index.html", "My Section Bundle Content Content.")
b.EditFileReplaceAll("content/mysection/mysectionbundle/mysectionbundlecontent.md", "Content Content.", "Content Content Edited.").Build()
b.AssertFileContent("public/mysection/mysectionbundle/index.html", "My Section Bundle Content Content Edited.")
}
func TestRebuildRenameTextFileInBranchBundle(t *testing.T) {
b := TestRunning(t, rebuildFilesSimple)
b.AssertFileContent("public/mysection/index.html", "My Section")