Skip to content

Commit

Permalink
Fix rebuild of changed bundled content files
Browse files Browse the repository at this point in the history
Fixes #12000
  • Loading branch information
bep committed Feb 6, 2024
1 parent 146aedd commit a65622a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
5 changes: 5 additions & 0 deletions common/paths/pathparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 17 additions & 1 deletion hugolib/content_map_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,30 @@ 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 {
ids = append(ids, id)
return false
})
}

if n := t.treeResources.Get(key); n != nil {
n.ForEeachIdentity(func(id identity.Identity) bool {
ids = append(ids, id)
Expand Down
5 changes: 1 addition & 4 deletions hugolib/hugo_sites_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}

Expand All @@ -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())
Expand Down
5 changes: 5 additions & 0 deletions hugolib/pages_capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
}
Expand Down
11 changes: 9 additions & 2 deletions hugolib/rebuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit a65622a

Please sign in to comment.