URI: 
       Make sure replaced pages gets marked as stale - hugo - [fork] hugo port for 9front
  HTML git clone git@git.drkhsh.at/hugo.git
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
   DIR README
   DIR LICENSE
       ---
   DIR commit 9dd687027f2b37bdb94d51fed403066b9f7b9a45
   DIR parent 196132753649e6e714f05c83122737cabd0da310
  HTML Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
       Date:   Tue, 30 Apr 2024 18:25:55 +0200
       
       Make sure replaced pages gets marked as stale
       
       Fixes #12436
       
       Diffstat:
         M hugolib/content_map_page.go         |      14 ++++++++++++--
         M hugolib/rebuild_test.go             |      36 +++++++++++++++++++++++++++++++
         M hugolib/site_benchmark_new_test.go  |       2 +-
       
       3 files changed, 49 insertions(+), 3 deletions(-)
       ---
   DIR diff --git a/hugolib/content_map_page.go b/hugolib/content_map_page.go
       @@ -824,6 +824,9 @@ func (s *contentNodeShifter) Insert(old, new contentNodeI) contentNodeI {
                        if !ok {
                                panic(fmt.Sprintf("unknown type %T", new))
                        }
       +                if newp != old {
       +                        resource.MarkStale(old)
       +                }
                        if vv.s.languagei == newp.s.languagei {
                                return new
                        }
       @@ -836,7 +839,11 @@ func (s *contentNodeShifter) Insert(old, new contentNodeI) contentNodeI {
                        if !ok {
                                panic(fmt.Sprintf("unknown type %T", new))
                        }
       -                resource.MarkStale(vv[newp.s.languagei])
       +                oldp := vv[newp.s.languagei]
       +                if oldp != newp {
       +                        resource.MarkStale(oldp)
       +                }
       +
                        vv[newp.s.languagei] = new
                        return vv
                case *resourceSource:
       @@ -856,7 +863,10 @@ func (s *contentNodeShifter) Insert(old, new contentNodeI) contentNodeI {
                        if !ok {
                                panic(fmt.Sprintf("unknown type %T", new))
                        }
       -                resource.MarkStale(vv[newp.LangIndex()])
       +                oldp := vv[newp.LangIndex()]
       +                if oldp != newp {
       +                        resource.MarkStale(oldp)
       +                }
                        vv[newp.LangIndex()] = newp
                        return vv
                default:
   DIR diff --git a/hugolib/rebuild_test.go b/hugolib/rebuild_test.go
       @@ -1585,3 +1585,39 @@ title: p1
                b.AddFiles("content/p2.md", "---\ntitle: p2\n---").Build()
                b.AssertFileContent("public/index.html", "p1|p2|") // this test passes, which doesn't match reality
        }
       +
       +func TestRebuildHomeThenPageIssue12436(t *testing.T) {
       +        t.Parallel()
       +
       +        files := `
       +-- hugo.toml --
       +baseURL = "https://example.com"
       +disableKinds = ['sitemap','taxonomy','term']
       +disableLiveReload = true
       +-- layouts/_default/list.html --
       +{{ .Content }}
       +-- layouts/_default/single.html --
       +{{ .Content }}
       +-- content/_index.md --
       +---
       +title: home
       +---
       +home-content|
       +-- content/p1/index.md --
       +---
       +title: p1
       +---
       +p1-content|
       +`
       +
       +        b := TestRunning(t, files)
       +
       +        b.AssertFileContent("public/index.html", "home-content|")
       +        b.AssertFileContent("public/p1/index.html", "p1-content|")
       +
       +        b.EditFileReplaceAll("content/_index.md", "home-content", "home-content-foo").Build()
       +        b.AssertFileContent("public/index.html", "home-content-foo")
       +
       +        b.EditFileReplaceAll("content/p1/index.md", "p1-content", "p1-content-foo").Build()
       +        b.AssertFileContent("public/p1/index.html", "p1-content-foo")
       +}
   DIR diff --git a/hugolib/site_benchmark_new_test.go b/hugolib/site_benchmark_new_test.go
       @@ -487,7 +487,7 @@ Edited!!`, p.Title()))
        
                // We currently rebuild all the language versions of the same content file.
                // We could probably optimize that case, but it's not trivial.
       -        b.Assert(int(counters.contentRenderCounter.Load()), qt.Equals, 4)
       +        b.Assert(int(counters.contentRenderCounter.Load()), qt.Equals, 33)
                b.AssertFileContent("public"+p.RelPermalink()+"index.html", "Edited!!")
        }