Skip to content

Commit 0f1c7d1

Browse files
bepclaude
andauthored
Fix template change detection for multi-version sites
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 <[email protected]>
1 parent 1035233 commit 0f1c7d1

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

hugolib/hugo_sites.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -531,17 +531,8 @@ func (h *HugoSites) resetLogs() {
531531
}
532532
}
533533

534-
func (h *HugoSites) withSite(fn func(s *Site) error) error {
535-
for _, s := range h.Sites {
536-
if err := fn(s); err != nil {
537-
return err
538-
}
539-
}
540-
return nil
541-
}
542-
543534
func (h *HugoSites) withPage(fn func(s string, p *pageState) bool) {
544-
h.withSite(func(s *Site) error {
535+
for s := range h.allSites(nil) {
545536
w := &doctree.NodeShiftTreeWalker[contentNode]{
546537
Tree: s.pageMap.treePages,
547538
LockType: doctree.LockTypeRead,
@@ -552,8 +543,8 @@ func (h *HugoSites) withPage(fn func(s string, p *pageState) bool) {
552543
return radix.WalkContinue, nil
553544
},
554545
}
555-
return w.Walk(context.Background())
556-
})
546+
_ = w.Walk(context.Background())
547+
}
557548
}
558549

559550
// BuildCfg holds build options used to, as an example, skip the render step.

hugolib/sitesmatrix/sitematrix_integration_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,3 +1637,24 @@ Title: {{ .Title }}|Version: {{ .Site.Version.Name }}|
16371637

16381638
b.AssertFileContent("public/v1/p1/index.html", "Title: P1 from theme|Version: v1|")
16391639
}
1640+
1641+
func TestSitesMatrixVersionsEditTemplate(t *testing.T) {
1642+
files := `
1643+
-- hugo.toml --
1644+
defaultcontentVersion = "v1"
1645+
defaultcontentVersionInSubDir = true
1646+
[versions]
1647+
[versions."v1"]
1648+
[versions."v2"]
1649+
-- layouts/all.html --
1650+
Version: {{ .Site.Version.Name }}|
1651+
`
1652+
1653+
b := hugolib.TestRunning(t, files)
1654+
1655+
b.AssertFileContent("public/v1/index.html", "Version: v1|")
1656+
1657+
b.EditFileReplaceAll("layouts/all.html", "Version:", "Edited version:").Build()
1658+
1659+
b.AssertFileContent("public/v1/index.html", "Edited version: v1|")
1660+
}

0 commit comments

Comments
 (0)