hugolib: Fix taxonomies vs expired
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 15 Aug 2019 07:47:25 +0000 (09:47 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 15 Aug 2019 07:52:08 +0000 (09:52 +0200)
In Hugo 0.57 we needed to delay the page metadata initialization until we had built the page graph.

This introduced a regression in that we now created taxonomy entries for expired pages.

This fixes that by moving the "should not build" filter before we assemble the taxonomies.

Fixes #6213

hugolib/pagecollections.go
hugolib/pages_map.go
hugolib/taxonomy_test.go

index 4b00642526708d9e7e11d8cc01beeef10870b004..01a194ac1f8a6b5695ff9e3136ccd9034d5ca98b 100644 (file)
@@ -466,14 +466,6 @@ func (c *PageCollections) createWorkAllPages() error {
                        }
                }
 
-               tmp := bucket.pages[:0]
-               for _, x := range bucket.pages {
-                       if c.pagesMap.s.shouldBuild(x) {
-                               tmp = append(tmp, x)
-                       }
-               }
-               bucket.pages = tmp
-
                if bucket.isEmpty() {
                        if bucket.owner.IsSection() && bucket.owner.File().IsZero() {
                                // Check for any nested section.
index 26bbedec6df39b37f2f174f403ee61358a7c2e9d..c7a74c4c11c3bd84e30a7f015aae8c87c6e129d0 100644 (file)
@@ -100,6 +100,17 @@ func (m *pagesMap) initPageMetaFor(prefix string, bucket *pagesMapBucket) error
                                }
                        }
                }
+
+               // Now that the metadata is initialized (with dates, draft set etc.)
+               // we can remove the pages that we for some reason should not include
+               // in this build.
+               tmp := bucket.pages[:0]
+               for _, x := range bucket.pages {
+                       if m.s.shouldBuild(x) {
+                               tmp = append(tmp, x)
+                       }
+               }
+               bucket.pages = tmp
        }
 
        return nil
index ccad3a2075deca44dfa280619770e9102111cb86..294e4f1a0db9bffbaa5daf349fb29f30ea62e771 100644 (file)
@@ -320,3 +320,35 @@ Content.
        b.AssertFileContent("public/tags/index.html", `<li><a href="http://example.com/tags/rocks-i-say/">Rocks I say!</a> 10</li>`)
 
 }
+
+// Issue 6213
+func TestTaxonomiesNotForDrafts(t *testing.T) {
+       t.Parallel()
+
+       b := newTestSitesBuilder(t)
+       b.WithContent("draft.md", `---
+title: "Draft"
+draft: true
+categories: ["drafts"]
+---
+
+`,
+               "regular.md", `---
+title: "Not Draft"
+categories: ["regular"]
+---
+
+`)
+
+       b.Build(BuildCfg{})
+       s := b.H.Sites[0]
+
+       b.Assert(b.CheckExists("public/categories/regular/index.html"), qt.Equals, true)
+       b.Assert(b.CheckExists("public/categories/drafts/index.html"), qt.Equals, false)
+
+       reg, _ := s.getPageNew(nil, "categories/regular")
+       dra, _ := s.getPageNew(nil, "categories/draft")
+       b.Assert(reg, qt.Not(qt.IsNil))
+       b.Assert(dra, qt.IsNil)
+
+}