Fix panic when home page is drafted
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 22 Feb 2020 17:22:40 +0000 (18:22 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 22 Feb 2020 23:11:10 +0000 (00:11 +0100)
Fixes #6927

hugolib/content_map_page.go
hugolib/taxonomy_test.go

index 143de535115b081e52e12468b1403676c8f3f634..c605362858d967c18aed3b99c1c74b8fcde9b39b 100644 (file)
@@ -719,6 +719,12 @@ func (m *pageMaps) AssemblePages() error {
                        return err
                }
 
+               if pm.s.home == nil {
+                       // Home is disabled, everything is.
+                       pm.bundleTrees.DeletePrefix("")
+                       return nil
+               }
+
                if err := pm.assembleTaxonomies(); err != nil {
                        return err
                }
index 0e2f0d83d5d16e853dba8e7ff259d740e7255b17..f8dca6a1f384096022adad59a4a367936343c6ab 100644 (file)
@@ -401,6 +401,50 @@ Content.
 
 }
 
+// https://github.com/gohugoio/hugo/issues/6927
+func TestTaxonomiesHomeDraft(t *testing.T) {
+       t.Parallel()
+
+       b := newTestSitesBuilder(t)
+       b.WithContent(
+               "_index.md", `---
+title: "Home"
+draft: true
+---
+
+Content.
+
+`,
+               "posts/_index.md", `---
+title: "Posts"
+draft: true
+---
+
+Content.
+
+`,
+               "posts/page.md", `---
+title: "The Page"
+categories: ["cool"]
+---
+
+Content.
+
+`,
+       )
+
+       b.WithTemplates("index.html", `
+NO HOME FOR YOU
+`)
+
+       b.Build(BuildCfg{})
+
+       b.Assert(b.CheckExists("public/index.html"), qt.Equals, false)
+       b.Assert(b.CheckExists("public/categories/index.html"), qt.Equals, false)
+       b.Assert(b.CheckExists("public/posts/index.html"), qt.Equals, false)
+
+}
+
 // https://github.com/gohugoio/hugo/issues/6173
 func TestTaxonomiesWithBundledResources(t *testing.T) {
        b := newTestSitesBuilder(t)