]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Fix rebuild of changed bundled content files
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 6 Feb 2024 19:26:18 +0000 (20:26 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 6 Feb 2024 20:53:33 +0000 (21:53 +0100)
Fixes #12000

common/paths/pathparser.go
hugolib/content_map_page.go
hugolib/hugo_sites_build.go
hugolib/pages_capture.go
hugolib/rebuild_test.go

index f506eb60fbcfd7e41c19c72b09333bb93074db24..eceb46b3d581fb35403730fb968c9b503d98cb21 100644 (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 {
index 75863acbd8a9f0d05f759eda92d50d603c755976..43c67ce738a51106d409128675568a87d407b6f1 100644 (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)
index 4b22c19563cc541a28b7e86e2e9ea38210c39d3b..17af2d8d8dc0c2562a6d897a1308545d9063d766 100644 (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())
index b7da065fdc5969d0cf59f7fe1cc7e2727dee2d6c..a7f8faaf0b44966d68fd0a49d2fe828000268bde 100644 (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()
                                })
                        }
index 74b04fe0116577015cc911df99b63edd9767eaf8..b1ebe14d53aae531d20d21691647b7453b7020e2 100644 (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")