Skip to content

Commit

Permalink
hugolib: Fix Pages reinitialization on rebuilds
Browse files Browse the repository at this point in the history
Which had some unpredictable behaviour when using `.Pages` on home page etc. that had a content page.

Fixes #5833
  • Loading branch information
bep committed Apr 17, 2019
1 parent 2957795 commit 9b17cbb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
12 changes: 9 additions & 3 deletions hugolib/hugo_sites_rebuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, `
---
Expand All @@ -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>")

}
8 changes: 6 additions & 2 deletions hugolib/page__common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
1 change: 1 addition & 0 deletions hugolib/page__new.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions hugolib/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 9b17cbb

Please sign in to comment.