hugolib: Fix Pages reinitialization on rebuilds
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 17 Apr 2019 08:36:36 +0000 (10:36 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 17 Apr 2019 10:56:46 +0000 (12:56 +0200)
Which had some unpredictable behaviour when using `.Pages` on home page etc. that had a content page.

Fixes #5833

hugolib/hugo_sites_rebuild_test.go
hugolib/page__common.go
hugolib/page__new.go
hugolib/site.go

index c2acbc238072cd08cb8e4d708fd57f17ebc934e5..4a81fe950f9a0a9d0e0de66502e89a060846a2fb 100644 (file)
@@ -52,13 +52,16 @@ Content.
 
        b.WithTemplatesAdded("index.html", `
 {{ range (.Paginate .Site.RegularPages).Pages }}
-* Page: {{ .Title }}|Summary: {{ .Summary }}|Content: {{ .Content }}
+* Page Paginate: {{ .Title }}|Summary: {{ .Summary }}|Content: {{ .Content }}
+{{ end }}
+{{ range .Pages }}
+* Page Pages: {{ .Title }}|Summary: {{ .Summary }}|Content: {{ .Content }}
 {{ end }}
 `)
 
        b.Running().Build(BuildCfg{})
 
-       b.AssertFileContent("public/index.html", "* Page: Page 1|Summary: Initial summary|Content: <p>Content.</p>")
+       b.AssertFileContent("public/index.html", "* Page Paginate: Page 1|Summary: Initial summary|Content: <p>Content.</p>")
 
        b.EditFiles(contentFilename, `
 ---
@@ -72,6 +75,9 @@ Edited content.
 
        b.Build(BuildCfg{})
 
-       b.AssertFileContent("public/index.html", "* Page: Page 1 edit|Summary: Edited summary|Content: <p>Edited content.</p>")
+       b.AssertFileContent("public/index.html", "* Page Paginate: Page 1 edit|Summary: Edited summary|Content: <p>Edited content.</p>")
+
+       // https://github.com/gohugoio/hugo/issues/5833
+       b.AssertFileContent("public/index.html", "* Page Pages: Page 1 edit|Summary: Edited summary|Content: <p>Edited content.</p>")
 
 }
index 01280bb407ced032027746546214eafbacca2598..f9ceee8c9056918409762ba64e1e43a6e0aa1621 100644 (file)
@@ -87,8 +87,7 @@ type pageCommon struct {
        page.InternalDependencies
 
        // The children. Regular pages will have none.
-       pages     page.Pages
-       pagesInit sync.Once
+       *pagePages
 
        // Any bundled resources
        resources            resource.Resources
@@ -111,3 +110,8 @@ type pageCommon struct {
        // Set in fast render mode to force render a given page.
        forceRender bool
 }
+
+type pagePages struct {
+       pages     page.Pages
+       pagesInit sync.Once
+}
index 0ac14a5e819af05c624075c22114a5225f6c910e..c703867f170b9c48078f95d72d222565274215a9 100644 (file)
@@ -57,6 +57,7 @@ func newPageBase(metaProvider *pageMeta) (*pageState, error) {
                        RefProvider:             page.NopPage,
                        ShortcodeInfoProvider:   page.NopPage,
                        LanguageProvider:        s,
+                       pagePages:               &pagePages{},
 
                        InternalDependencies: s,
                        init:                 lazy.New(),
index 47ca77016b19bbc9b3b6ccf3983ab11616e3881e..693c79f6766278b8bda2190a6d4c7eed3a080d51 100644 (file)
@@ -1630,6 +1630,7 @@ func (s *Site) resetBuildState() {
        s.init.Reset()
 
        for _, p := range s.rawAllPages {
+               p.pagePages = &pagePages{}
                p.subSections = page.Pages{}
                p.parent = nil
                p.Scratcher = maps.NewScratcher()