node to page: Handle sections with only _index.md
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 10 Nov 2016 11:26:23 +0000 (12:26 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 22 Nov 2016 08:57:03 +0000 (09:57 +0100)
Updates #2297

hugolib/node_as_page_test.go
hugolib/site.go

index b871c3016ebe853593d1bb2814f2349089247f3f..d6645bc54ce4c9120771becdf5c8777e3d8a032f 100644 (file)
@@ -116,6 +116,7 @@ Content Page %02d
                "Pag: Page 02")
 
        sections := h.findAllPagesByNodeType(NodeSection)
+
        require.Len(t, sections, 2)
 
        // Check taxonomy lists
@@ -352,8 +353,6 @@ menu:
 }
 
 func TestNodesWithAlias(t *testing.T) {
-       //jww.SetStdoutThreshold(jww.LevelDebug)
-       //defer jww.SetStdoutThreshold(jww.LevelFatal)
        testCommonResetState()
 
        writeLayoutsForNodeAsPageTests(t)
@@ -380,6 +379,30 @@ aliases:
 
 }
 
+func TestNodesWithSectionWithIndexPageOnly(t *testing.T) {
+       testCommonResetState()
+
+       writeLayoutsForNodeAsPageTests(t)
+
+       writeSource(t, filepath.Join("content", "sect", "_index.md"), `---
+title: MySection
+---
+My Section Content
+`)
+
+       viper.Set("paginate", 1)
+       viper.Set("title", "Hugo Rocks!")
+
+       s := newSiteDefaultLang()
+
+       if err := buildAndRenderSite(s); err != nil {
+               t.Fatalf("Failed to build site: %s", err)
+       }
+
+       assertFileContent(t, filepath.Join("public", "sect", "index.html"), true, "My Section")
+
+}
+
 func writeRegularPagesForNodeAsPageTests(t *testing.T) {
        writeRegularPagesForNodeAsPageTestsWithLang(t, "")
 }
index 30674ad8e0829c181cb4e067645787348df81d75..3e1c92d9fbeee12bc14f06d568554e843acbb9a1 100644 (file)
@@ -1351,8 +1351,8 @@ func (s *Site) buildSiteMeta() (err error) {
        // assembleSections: Needs pages (temp lookup)
        s.assembleSections()
 
-       // TODO(bep) np
-       pages := s.findPagesByNodeType(NodePage)
+       // TODO(bep) np Site.LastMod
+       pages := s.Nodes
        s.Info.LastChange = pages[0].Lastmod
 
        return
@@ -1541,11 +1541,21 @@ func (s *Site) resetBuildState() {
 func (s *Site) assembleSections() {
        s.Sections = make(Taxonomy)
        s.Info.Sections = s.Sections
+       // TODO(bep) np check these vs the caches
        regularPages := s.findPagesByNodeType(NodePage)
+       sectionPages := s.findPagesByNodeType(NodeSection)
+
        for i, p := range regularPages {
                s.Sections.add(p.Section(), WeightedPage{regularPages[i].Weight, regularPages[i]}, s.Info.preserveTaxonomyNames)
        }
 
+       // Add sections without regular pages, but with a content page
+       for _, sectionPage := range sectionPages {
+               if _, ok := s.Sections[sectionPage.sections[0]]; !ok {
+                       s.Sections[sectionPage.sections[0]] = WeightedPages{}
+               }
+       }
+
        for k := range s.Sections {
                s.Sections[k].Sort()