Skip to content

Commit 9dd6870

Browse files
committed
Make sure replaced pages gets marked as stale
Fixes #12436
1 parent 1961327 commit 9dd6870

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

hugolib/content_map_page.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,9 @@ func (s *contentNodeShifter) Insert(old, new contentNodeI) contentNodeI {
824824
if !ok {
825825
panic(fmt.Sprintf("unknown type %T", new))
826826
}
827+
if newp != old {
828+
resource.MarkStale(old)
829+
}
827830
if vv.s.languagei == newp.s.languagei {
828831
return new
829832
}
@@ -836,7 +839,11 @@ func (s *contentNodeShifter) Insert(old, new contentNodeI) contentNodeI {
836839
if !ok {
837840
panic(fmt.Sprintf("unknown type %T", new))
838841
}
839-
resource.MarkStale(vv[newp.s.languagei])
842+
oldp := vv[newp.s.languagei]
843+
if oldp != newp {
844+
resource.MarkStale(oldp)
845+
}
846+
840847
vv[newp.s.languagei] = new
841848
return vv
842849
case *resourceSource:
@@ -856,7 +863,10 @@ func (s *contentNodeShifter) Insert(old, new contentNodeI) contentNodeI {
856863
if !ok {
857864
panic(fmt.Sprintf("unknown type %T", new))
858865
}
859-
resource.MarkStale(vv[newp.LangIndex()])
866+
oldp := vv[newp.LangIndex()]
867+
if oldp != newp {
868+
resource.MarkStale(oldp)
869+
}
860870
vv[newp.LangIndex()] = newp
861871
return vv
862872
default:

hugolib/rebuild_test.go

+36
Original file line numberDiff line numberDiff line change
@@ -1585,3 +1585,39 @@ title: p1
15851585
b.AddFiles("content/p2.md", "---\ntitle: p2\n---").Build()
15861586
b.AssertFileContent("public/index.html", "p1|p2|") // this test passes, which doesn't match reality
15871587
}
1588+
1589+
func TestRebuildHomeThenPageIssue12436(t *testing.T) {
1590+
t.Parallel()
1591+
1592+
files := `
1593+
-- hugo.toml --
1594+
baseURL = "https://example.com"
1595+
disableKinds = ['sitemap','taxonomy','term']
1596+
disableLiveReload = true
1597+
-- layouts/_default/list.html --
1598+
{{ .Content }}
1599+
-- layouts/_default/single.html --
1600+
{{ .Content }}
1601+
-- content/_index.md --
1602+
---
1603+
title: home
1604+
---
1605+
home-content|
1606+
-- content/p1/index.md --
1607+
---
1608+
title: p1
1609+
---
1610+
p1-content|
1611+
`
1612+
1613+
b := TestRunning(t, files)
1614+
1615+
b.AssertFileContent("public/index.html", "home-content|")
1616+
b.AssertFileContent("public/p1/index.html", "p1-content|")
1617+
1618+
b.EditFileReplaceAll("content/_index.md", "home-content", "home-content-foo").Build()
1619+
b.AssertFileContent("public/index.html", "home-content-foo")
1620+
1621+
b.EditFileReplaceAll("content/p1/index.md", "p1-content", "p1-content-foo").Build()
1622+
b.AssertFileContent("public/p1/index.html", "p1-content-foo")
1623+
}

hugolib/site_benchmark_new_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ Edited!!`, p.Title()))
487487

488488
// We currently rebuild all the language versions of the same content file.
489489
// We could probably optimize that case, but it's not trivial.
490-
b.Assert(int(counters.contentRenderCounter.Load()), qt.Equals, 4)
490+
b.Assert(int(counters.contentRenderCounter.Load()), qt.Equals, 33)
491491
b.AssertFileContent("public"+p.RelPermalink()+"index.html", "Edited!!")
492492
}
493493

0 commit comments

Comments
 (0)