Skip to content

Commit

Permalink
hugolib: Fix .Site.GetPage regression
Browse files Browse the repository at this point in the history
In Hugo 0.44 we simplified the `.Site.GetPage` API and added code to handle the old-style syntax in most cases.

This logic did not handle the lookup of the home page via `.Site.GetPage "section" ""` and similar. This commit fixes that.

Fixes #4989
  • Loading branch information
bep committed Jul 24, 2018
1 parent 016dd4a commit 04d4c08
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion hugolib/page_collections.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,14 @@ func (c *PageCollections) getPageOldVersion(ref ...string) (*Page, error) {
if len(refs) == 0 || refs[0] == KindHome {
key = "/"
} else if len(refs) == 1 {
key = refs[0]
if len(ref) == 2 && refs[0] == KindSection {
// This is an old style reference to the "Home Page section".
// Typically fetched via {{ .Site.GetPage "section" .Section }}
// See https://github.com/gohugoio/hugo/issues/4989
key = "/"
} else {
key = refs[0]
}
} else {
key = refs[1]
}
Expand Down
2 changes: 2 additions & 0 deletions hugolib/site_sections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ Content
{{ range .Paginator.Pages }}
PAG|{{ .Title }}|{{ $sect.InSection . }}
{{ end }}
{{/* https://github.com/gohugoio/hugo/issues/4989 */}}
{{ $sections := (.Site.GetPage "section" .Section).Sections.ByWeight }}
</html>`)

cfg.Set("paginate", 2)
Expand Down

0 comments on commit 04d4c08

Please sign in to comment.