diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2016-11-01 22:39:24 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2016-11-22 09:57:03 +0100 |
commit | 75c38071d8c61e2e1a56ae1949766b4144b68305 (patch) | |
tree | 4a73c2bffaafc7f151db5f6538e998fc7ddc184b /hugolib/node_as_page_test.go | |
parent | f8bda16e154465c74a2cc42dd8149369e19f7833 (diff) |
node to page: Create pages for nodes without content
Updates #2297
Diffstat (limited to 'hugolib/node_as_page_test.go')
-rw-r--r-- | hugolib/node_as_page_test.go | 150 |
1 files changed, 108 insertions, 42 deletions
diff --git a/hugolib/node_as_page_test.go b/hugolib/node_as_page_test.go index 090323cec..9c8506503 100644 --- a/hugolib/node_as_page_test.go +++ b/hugolib/node_as_page_test.go @@ -49,6 +49,8 @@ func TestNodesAsPage(t *testing.T) { testCommonResetState() + writeLayoutsForNodeAsPageTests(t) + writeSource(t, filepath.Join("content", "_node.md"), `--- title: Home Sweet Home! --- @@ -85,48 +87,6 @@ title: Taxonomy Term Categories Taxonomy Term Categories **Content!** `) - writeSource(t, filepath.Join("layouts", "index.html"), ` -Index Title: {{ .Title }} -Index Content: {{ .Content }} -# Pages: {{ len .Data.Pages }} -{{ range .Paginator.Pages }} - Pag: {{ .Title }} -{{ end }} -`) - - writeSource(t, filepath.Join("layouts", "_default", "single.html"), ` -Single Title: {{ .Title }} -Single Content: {{ .Content }} -`) - - writeSource(t, filepath.Join("layouts", "_default", "section.html"), ` -Section Title: {{ .Title }} -Section Content: {{ .Content }} -# Pages: {{ len .Data.Pages }} -{{ range .Paginator.Pages }} - Pag: {{ .Title }} -{{ end }} -`) - - // Taxonomy lists - writeSource(t, filepath.Join("layouts", "_default", "taxonomy.html"), ` -Taxonomy Title: {{ .Title }} -Taxonomy Content: {{ .Content }} -# Pages: {{ len .Data.Pages }} -{{ range .Paginator.Pages }} - Pag: {{ .Title }} -{{ end }} -`) - - // Taxonomy terms - writeSource(t, filepath.Join("layouts", "_default", "terms.html"), ` -Taxonomy Terms Title: {{ .Title }} -Taxonomy Terms Content: {{ .Content }} -{{ range $key, $value := .Data.Terms }} - k/v: {{ $key }} / {{ printf "%=v" $value }} -{{ end }} -`) - // Add some regular pages for i := 1; i <= 4; i++ { sect := "sect1" @@ -213,3 +173,109 @@ Content Page %02d // There are no pages to paginate over in the taxonomy terms. } + +func TestNodesWithNoContentFile(t *testing.T) { + //jww.SetStdoutThreshold(jww.LevelDebug) + jww.SetStdoutThreshold(jww.LevelFatal) + + nodePageFeatureFlag = true + defer toggleNodePageFeatureFlag() + + testCommonResetState() + + writeLayoutsForNodeAsPageTests(t) + + for i := 1; i <= 4; i++ { + sect := "sect1" + if i > 2 { + sect = "sect2" + } + writeSource(t, filepath.Join("content", sect, fmt.Sprintf("regular%d.md", i)), fmt.Sprintf(`--- +title: Page %02d +categories: [ + "Hugo", + "Web" +] +--- +Content Page %02d +`, i, i)) + } + + 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) + } + + // Home page + homePages := s.findPagesByNodeType(NodeHome) + require.Len(t, homePages, 1) + + homePage := homePages[0] + require.Len(t, homePage.Data["Pages"], 4) + + assertFileContent(t, filepath.Join("public", "index.html"), false, + "Index Title: Hugo Rocks!") + + // Taxonomy list + assertFileContent(t, filepath.Join("public", "categories", "hugo", "index.html"), false, + "Taxonomy Title: Hugo") + + // Taxonomy terms + assertFileContent(t, filepath.Join("public", "categories", "index.html"), false, + "Taxonomy Terms Title: Categories") + + // Sections + assertFileContent(t, filepath.Join("public", "sect1", "index.html"), false, + "Section Title: Sect1s") + assertFileContent(t, filepath.Join("public", "sect2", "index.html"), false, + "Section Title: Sect2s") + +} + +func writeLayoutsForNodeAsPageTests(t *testing.T) { + writeSource(t, filepath.Join("layouts", "index.html"), ` +Index Title: {{ .Title }} +Index Content: {{ .Content }} +# Pages: {{ len .Data.Pages }} +{{ range .Paginator.Pages }} + Pag: {{ .Title }} +{{ end }} +`) + + writeSource(t, filepath.Join("layouts", "_default", "single.html"), ` +Single Title: {{ .Title }} +Single Content: {{ .Content }} +`) + + writeSource(t, filepath.Join("layouts", "_default", "section.html"), ` +Section Title: {{ .Title }} +Section Content: {{ .Content }} +# Pages: {{ len .Data.Pages }} +{{ range .Paginator.Pages }} + Pag: {{ .Title }} +{{ end }} +`) + + // Taxonomy lists + writeSource(t, filepath.Join("layouts", "_default", "taxonomy.html"), ` +Taxonomy Title: {{ .Title }} +Taxonomy Content: {{ .Content }} +# Pages: {{ len .Data.Pages }} +{{ range .Paginator.Pages }} + Pag: {{ .Title }} +{{ end }} +`) + + // Taxonomy terms + writeSource(t, filepath.Join("layouts", "_default", "terms.html"), ` +Taxonomy Terms Title: {{ .Title }} +Taxonomy Terms Content: {{ .Content }} +{{ range $key, $value := .Data.Terms }} + k/v: {{ $key }} / {{ printf "%=v" $value }} +{{ end }} +`) +} |