From 640b8bed21eabfd6e256814eab4b3ab3ad2e3354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Thu, 10 Nov 2016 12:26:23 +0100 Subject: [PATCH] node to page: Handle sections with only _index.md Updates #2297 --- hugolib/node_as_page_test.go | 27 +++++++++++++++++++++++++-- hugolib/site.go | 14 ++++++++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/hugolib/node_as_page_test.go b/hugolib/node_as_page_test.go index b871c3016..d6645bc54 100644 --- a/hugolib/node_as_page_test.go +++ b/hugolib/node_as_page_test.go @@ -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, "") } diff --git a/hugolib/site.go b/hugolib/site.go index 30674ad8e..3e1c92d9f 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -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()