Skip to content

Commit dd9b1ba

Browse files
committed
hugolib: Make .Site.Sections return the top level sections
See #3591
1 parent 1039356 commit dd9b1ba

File tree

2 files changed

+8
-24
lines changed

2 files changed

+8
-24
lines changed

‎hugolib/site_sections.go‎

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,16 @@ import (
1919
"strconv"
2020
"strings"
2121

22-
"github.com/gohugoio/hugo/helpers"
2322
radix "github.com/hashicorp/go-immutable-radix"
2423
)
2524

26-
// Deprecated: Use .Site.Home.Sections.
27-
// TODO(bep) Hugo 0.23 = Reuse as an alias for home's sections.
28-
func (s *SiteInfo) Sections() Taxonomy {
29-
30-
helpText := `In Hugo 0.22 we introduced nested sections, so this method now returns an empty taxonomy.
31-
32-
To list sections with its pages, you can do something like this:
33-
34-
{{ range $.Site.Home.Sections }}
35-
Section: {{ .Title }}
36-
{{ range .Pages }}
37-
Section Page: {{ .Title }}
38-
{{ end }}
39-
{{ end }}
40-
41-
To get a specific section, you can do this:
42-
43-
{{ $section := $.Site.GetPage "section" "blog" }}
44-
`
45-
46-
helpers.Deprecated("Site", "Sections", helpText, true)
47-
48-
return Taxonomy{}
25+
// Sections returns the top level sections.
26+
func (s *SiteInfo) Sections() Pages {
27+
home, err := s.Home()
28+
if err == nil {
29+
return home.Sections()
30+
}
31+
return nil
4932
}
5033

5134
// Home is a shortcut to the home page, equivalent to .Site.GetPage "home".

‎hugolib/site_sections_test.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
246246
assert.NotNil(home)
247247

248248
assert.Len(home.Sections(), 9)
249+
assert.Equal(home.Sections(), s.Info.Sections())
249250

250251
rootPage := s.getPage(KindPage, "mypage.md")
251252
assert.NotNil(rootPage)

0 commit comments

Comments
 (0)