]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Fix template change detection for multi-version sites
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 1 Feb 2026 21:24:52 +0000 (22:24 +0100)
committerGitHub <noreply@github.com>
Sun, 1 Feb 2026 21:24:52 +0000 (22:24 +0100)
When templates were edited in a multi-version/role setup, only pages
from the current site slice (h.Sites) were checked for dependencies,
not pages from all sites. Fix by changing withPage to iterate over
all sites using allSites.

Fixes #14461

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
hugolib/hugo_sites.go
hugolib/sitesmatrix/sitematrix_integration_test.go

index 82601a8673e620c978e49271785720b08292f5ad..ced4715cb977d1e5ed14494d416c235bc1f18cb7 100644 (file)
@@ -531,17 +531,8 @@ func (h *HugoSites) resetLogs() {
        }
 }
 
-func (h *HugoSites) withSite(fn func(s *Site) error) error {
-       for _, s := range h.Sites {
-               if err := fn(s); err != nil {
-                       return err
-               }
-       }
-       return nil
-}
-
 func (h *HugoSites) withPage(fn func(s string, p *pageState) bool) {
-       h.withSite(func(s *Site) error {
+       for s := range h.allSites(nil) {
                w := &doctree.NodeShiftTreeWalker[contentNode]{
                        Tree:     s.pageMap.treePages,
                        LockType: doctree.LockTypeRead,
@@ -552,8 +543,8 @@ func (h *HugoSites) withPage(fn func(s string, p *pageState) bool) {
                                return radix.WalkContinue, nil
                        },
                }
-               return w.Walk(context.Background())
-       })
+               _ = w.Walk(context.Background())
+       }
 }
 
 // BuildCfg holds build options used to, as an example, skip the render step.
index 874936931bf09a7a0988138f20d807ccc122edde..674a339509e1e4d30af646308f9bdb4e1cf71ede 100644 (file)
@@ -1637,3 +1637,24 @@ Title: {{ .Title }}|Version: {{ .Site.Version.Name }}|
 
        b.AssertFileContent("public/v1/p1/index.html", "Title: P1 from theme|Version: v1|")
 }
+
+func TestSitesMatrixVersionsEditTemplate(t *testing.T) {
+       files := `
+-- hugo.toml --
+defaultcontentVersion = "v1"
+defaultcontentVersionInSubDir = true
+[versions]
+[versions."v1"]
+[versions."v2"]
+-- layouts/all.html --
+Version: {{ .Site.Version.Name }}|
+`
+
+       b := hugolib.TestRunning(t, files)
+
+       b.AssertFileContent("public/v1/index.html", "Version: v1|")
+
+       b.EditFileReplaceAll("layouts/all.html", "Version:", "Edited version:").Build()
+
+       b.AssertFileContent("public/v1/index.html", "Edited version: v1|")
+}