hugolib: Fix HugoSites.createMissingPages

Previously it would only check for existing KindTaxonomyTerm pages
if the taxonomy had any terms defined.  So for a taxonomy with no terms
but a taxonomy terms page it would generate a second empty terms page.
This commit is contained in:
Anton Staaf
2017-03-03 16:00:11 -08:00
committed by Bjørn Erik Pedersen
parent d0e2a1fa14
commit 22c89dcb6c
2 changed files with 35 additions and 27 deletions

View File

@@ -322,21 +322,8 @@ func (h *HugoSites) createMissingPages() error {
taxonomyPages := s.findPagesByKind(KindTaxonomy)
taxonomyTermsPages := s.findPagesByKind(KindTaxonomyTerm)
for _, plural := range taxonomies {
tax := s.Taxonomies[plural]
foundTaxonomyTermsPage := false
for key := range tax {
foundTaxonomyPage := false
origKey := key
if s.Info.preserveTaxonomyNames {
key = s.PathSpec.MakePathSanitized(key)
}
for _, p := range taxonomyPages {
if p.sections[0] == plural && p.sections[1] == key {
foundTaxonomyPage = true
break
}
}
if s.isEnabled(KindTaxonomyTerm) {
foundTaxonomyTermsPage := false
for _, p := range taxonomyTermsPages {
if p.sections[0] == plural {
foundTaxonomyTermsPage = true
@@ -344,16 +331,6 @@ func (h *HugoSites) createMissingPages() error {
}
}
if s.isEnabled(KindTaxonomy) {
if !foundTaxonomyPage {
n := s.newTaxonomyPage(plural, origKey)
s.Pages = append(s.Pages, n)
newPages = append(newPages, n)
}
}
}
if s.isEnabled(KindTaxonomyTerm) {
if !foundTaxonomyTermsPage {
foundTaxonomyTermsPage = true
n := s.newTaxonomyTermsPage(plural)
@@ -361,6 +338,29 @@ func (h *HugoSites) createMissingPages() error {
newPages = append(newPages, n)
}
}
if s.isEnabled(KindTaxonomy) {
for key := range s.Taxonomies[plural] {
foundTaxonomyPage := false
origKey := key
if s.Info.preserveTaxonomyNames {
key = s.PathSpec.MakePathSanitized(key)
}
for _, p := range taxonomyPages {
if p.sections[0] == plural && p.sections[1] == key {
foundTaxonomyPage = true
break
}
}
if !foundTaxonomyPage {
n := s.newTaxonomyPage(plural, origKey)
s.Pages = append(s.Pages, n)
newPages = append(newPages, n)
}
}
}
}
}