@@ -175,6 +175,16 @@ type Page struct {
175175 // isn't accomanied by one.
176176 sections []string
177177
178+ // Will only be set for sections and regular pages.
179+ parent * Page
180+
181+ // When we create paginator pages, we create a copy of the original,
182+ // but keep track of it here.
183+ origOnCopy * Page
184+
185+ // Will only be set for section pages and the home page.
186+ subSections Pages
187+
178188 s * Site
179189
180190 // Pulled over from old Node. TODO(bep) reorg and group (embed)
@@ -228,6 +238,9 @@ func (p *Page) createLayoutDescriptor() output.LayoutDescriptor {
228238
229239 switch p .Kind {
230240 case KindSection :
241+ // In Hugo 0.22 we introduce nested sections, but we still only
242+ // use the first level to pick the correct template. This may change in
243+ // the future.
231244 section = p .sections [0 ]
232245 case KindTaxonomy , KindTaxonomyTerm :
233246 section = p .s .taxonomiesPluralSingular [p .sections [0 ]]
@@ -265,6 +278,11 @@ func (p *Page) IsHome() bool {
265278 return p .Kind == KindHome
266279}
267280
281+ // IsSection returns whether this is a section page.
282+ func (p * Page ) IsSection () bool {
283+ return p .Kind == KindSection
284+ }
285+
268286// IsPage returns whether this is a regular content page.
269287func (p * Page ) IsPage () bool {
270288 return p .Kind == KindPage
@@ -667,6 +685,9 @@ func (p *Page) Type() string {
667685 return "page"
668686}
669687
688+ // Section returns the first path element below the content root. Note that
689+ // since Hugo 0.22 we support nested sections, but this will always be the first
690+ // element of any nested path.
670691func (p * Page ) Section () string {
671692 if p .Kind == KindSection {
672693 return p .sections [0 ]
@@ -1100,10 +1121,6 @@ func (p *Page) HasMenuCurrent(menuID string, me *MenuEntry) bool {
11001121 if sectionPagesMenu != "" {
11011122 section := p .Section ()
11021123
1103- if ! p .s .Info .preserveTaxonomyNames {
1104- section = p .s .PathSpec .MakePathSanitized (section )
1105- }
1106-
11071124 if section != "" && sectionPagesMenu == menuID && section == me .Identifier {
11081125 return true
11091126 }
@@ -1415,59 +1432,54 @@ func (p *Page) prepareLayouts() error {
14151432}
14161433
14171434func (p * Page ) prepareData (s * Site ) error {
1418-
1419- var pages Pages
1420-
1421- p .Data = make (map [string ]interface {})
1422- switch p .Kind {
1423- case KindPage :
1424- case KindHome :
1425- pages = s .RegularPages
1426- case KindSection :
1427- sectionData , ok := s .Sections [p .Section ()]
1428- if ! ok {
1429- return fmt .Errorf ("Data for section %s not found" , p .Section ())
1430- }
1431- pages = sectionData .Pages ()
1432- case KindTaxonomy :
1433- plural := p .sections [0 ]
1434- term := p .sections [1 ]
1435-
1436- if s .Info .preserveTaxonomyNames {
1437- if v , ok := s .taxonomiesOrigKey [fmt .Sprintf ("%s-%s" , plural , term )]; ok {
1438- term = v
1435+ if p .Kind != KindSection {
1436+ var pages Pages
1437+ p .Data = make (map [string ]interface {})
1438+
1439+ switch p .Kind {
1440+ case KindPage :
1441+ case KindHome :
1442+ pages = s .RegularPages
1443+ case KindTaxonomy :
1444+ plural := p .sections [0 ]
1445+ term := p .sections [1 ]
1446+
1447+ if s .Info .preserveTaxonomyNames {
1448+ if v , ok := s .taxonomiesOrigKey [fmt .Sprintf ("%s-%s" , plural , term )]; ok {
1449+ term = v
1450+ }
14391451 }
1440- }
14411452
1442- singular := s .taxonomiesPluralSingular [plural ]
1443- taxonomy := s .Taxonomies [plural ].Get (term )
1444-
1445- p .Data [singular ] = taxonomy
1446- p .Data ["Singular" ] = singular
1447- p .Data ["Plural" ] = plural
1448- p .Data ["Term" ] = term
1449- pages = taxonomy .Pages ()
1450- case KindTaxonomyTerm :
1451- plural := p .sections [0 ]
1452- singular := s .taxonomiesPluralSingular [plural ]
1453-
1454- p .Data ["Singular" ] = singular
1455- p .Data ["Plural" ] = plural
1456- p .Data ["Terms" ] = s .Taxonomies [plural ]
1457- // keep the following just for legacy reasons
1458- p .Data ["OrderedIndex" ] = p .Data ["Terms" ]
1459- p .Data ["Index" ] = p .Data ["Terms" ]
1460-
1461- // A list of all KindTaxonomy pages with matching plural
1462- for _ , p := range s .findPagesByKind (KindTaxonomy ) {
1463- if p .sections [0 ] == plural {
1464- pages = append (pages , p )
1453+ singular := s .taxonomiesPluralSingular [plural ]
1454+ taxonomy := s .Taxonomies [plural ].Get (term )
1455+
1456+ p .Data [singular ] = taxonomy
1457+ p .Data ["Singular" ] = singular
1458+ p .Data ["Plural" ] = plural
1459+ p .Data ["Term" ] = term
1460+ pages = taxonomy .Pages ()
1461+ case KindTaxonomyTerm :
1462+ plural := p .sections [0 ]
1463+ singular := s .taxonomiesPluralSingular [plural ]
1464+
1465+ p .Data ["Singular" ] = singular
1466+ p .Data ["Plural" ] = plural
1467+ p .Data ["Terms" ] = s .Taxonomies [plural ]
1468+ // keep the following just for legacy reasons
1469+ p .Data ["OrderedIndex" ] = p .Data ["Terms" ]
1470+ p .Data ["Index" ] = p .Data ["Terms" ]
1471+
1472+ // A list of all KindTaxonomy pages with matching plural
1473+ for _ , p := range s .findPagesByKind (KindTaxonomy ) {
1474+ if p .sections [0 ] == plural {
1475+ pages = append (pages , p )
1476+ }
14651477 }
14661478 }
1467- }
14681479
1469- p .Data ["Pages" ] = pages
1470- p .Pages = pages
1480+ p .Data ["Pages" ] = pages
1481+ p .Pages = pages
1482+ }
14711483
14721484 // Now we know enough to set missing dates on home page etc.
14731485 p .updatePageDates ()
@@ -1736,11 +1748,8 @@ func (p *Page) setValuesForKind(s *Site) {
17361748 switch p .Kind {
17371749 case KindHome :
17381750 p .URLPath .URL = "/"
1739- case KindSection :
1740- p .URLPath .URL = "/" + p .sections [0 ] + "/"
1741- case KindTaxonomy :
1742- p .URLPath .URL = "/" + path .Join (p .sections ... ) + "/"
1743- case KindTaxonomyTerm :
1751+ case KindPage :
1752+ default :
17441753 p .URLPath .URL = "/" + path .Join (p .sections ... ) + "/"
17451754 }
17461755}
0 commit comments