hugolib: Fix HugoSites.createMissingPages
authorAnton Staaf <anton@socialhacker.com>
Sat, 4 Mar 2017 00:00:11 +0000 (16:00 -0800)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 4 Mar 2017 20:37:52 +0000 (21:37 +0100)
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.

hugolib/hugo_sites.go
hugolib/node_as_page_test.go

index f35c7ce063f5b7464998034f9e3895f3df7e4f85..0dfcdeb9b39571fec32d396673456419ef04504e 100644 (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)
+                                               }
+                                       }
+                               }
                        }
                }
 
index 922a0e81ec89676a60d9792a7fa5fbba7108177d..f063faf9ab9afb6b31df0c35dc286b8b9498fcbd 100644 (file)
@@ -96,14 +96,14 @@ func doTestNodeAsPage(t *testing.T, ugly, preserveTaxonomyNames bool) {
 
        require.Len(t, nodes, 8)
 
-       home := nodes[6] // oldest
+       home := nodes[7] // oldest
 
        require.True(t, home.IsHome())
        require.True(t, home.IsNode())
        require.False(t, home.IsPage())
        require.True(t, home.Path() != "")
 
-       section2 := nodes[4]
+       section2 := nodes[5]
        require.Equal(t, "Section2", section2.Title)
 
        pages := sites.findAllPagesByKind(KindPage)
@@ -720,6 +720,14 @@ lastMod : %q
 Taxonomy Term Categories **Content!**
 `, date.Add(13*24*time.Hour).Format(time.RFC822), date.Add(14*24*time.Hour).Format(time.RFC822)))
 
+       writeSource(t, fs, filepath.Join("content", "tags", filename), fmt.Sprintf(`---
+title: Taxonomy Term Tags
+date : %q
+lastMod : %q
+---
+Taxonomy Term Tags **Content!**
+`, date.Add(15*24*time.Hour).Format(time.RFC822), date.Add(16*24*time.Hour).Format(time.RFC822)))
+
 }
 
 func writeLayoutsForNodeAsPageTests(t *testing.T, fs *hugofs.Fs) {