Skip to content

Commit

Permalink
hugolib: Make .Site.Sections return the top level sections
Browse files Browse the repository at this point in the history
See #3591
  • Loading branch information
bep committed Jul 4, 2017
1 parent 1039356 commit dd9b1ba
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 24 deletions.
31 changes: 7 additions & 24 deletions hugolib/site_sections.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,16 @@ import (
"strconv"
"strings"

"github.com/gohugoio/hugo/helpers"
radix "github.com/hashicorp/go-immutable-radix"
)

// Deprecated: Use .Site.Home.Sections.
// TODO(bep) Hugo 0.23 = Reuse as an alias for home's sections.
func (s *SiteInfo) Sections() Taxonomy {

helpText := `In Hugo 0.22 we introduced nested sections, so this method now returns an empty taxonomy.
To list sections with its pages, you can do something like this:
{{ range $.Site.Home.Sections }}
Section: {{ .Title }}
{{ range .Pages }}
Section Page: {{ .Title }}
{{ end }}
{{ end }}
To get a specific section, you can do this:
{{ $section := $.Site.GetPage "section" "blog" }}
`

helpers.Deprecated("Site", "Sections", helpText, true)

return Taxonomy{}
// Sections returns the top level sections.
func (s *SiteInfo) Sections() Pages {
home, err := s.Home()
if err == nil {
return home.Sections()
}
return nil
}

// Home is a shortcut to the home page, equivalent to .Site.GetPage "home".
Expand Down
1 change: 1 addition & 0 deletions hugolib/site_sections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
assert.NotNil(home)

assert.Len(home.Sections(), 9)
assert.Equal(home.Sections(), s.Info.Sections())

rootPage := s.getPage(KindPage, "mypage.md")
assert.NotNil(rootPage)
Expand Down

0 comments on commit dd9b1ba

Please sign in to comment.