summaryrefslogtreecommitdiffstats
path: root/hugolib/site_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-08-15 12:11:49 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-08-15 20:21:57 +0200
commit67524c993623871626f0f22e6a2ac705a816a959 (patch)
tree17f18f6990461669ceed88bfacde353d32acca2f /hugolib/site_test.go
parent952a3194962dd91f87e5bd227a1591b00c39ff05 (diff)
Fix mainSections logic
Fixes #6217
Diffstat (limited to 'hugolib/site_test.go')
-rw-r--r--hugolib/site_test.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/hugolib/site_test.go b/hugolib/site_test.go
index 74424cd3d..6cbcbf8d5 100644
--- a/hugolib/site_test.go
+++ b/hugolib/site_test.go
@@ -20,6 +20,8 @@ import (
"strings"
"testing"
+ "github.com/spf13/viper"
+
"github.com/markbates/inflect"
"github.com/gohugoio/hugo/helpers"
@@ -364,6 +366,61 @@ func TestShouldNotWriteZeroLengthFilesToDestination(t *testing.T) {
th.assertFileNotExist(filepath.Join("public", "index.html"))
}
+func TestMainSections(t *testing.T) {
+ c := qt.New(t)
+ for _, paramSet := range []bool{false, true} {
+ c.Run(fmt.Sprintf("param-%t", paramSet), func(c *qt.C) {
+ v := viper.New()
+ if paramSet {
+ v.Set("params", map[string]interface{}{
+ "mainSections": []string{"a1", "a2"},
+ })
+ }
+
+ b := newTestSitesBuilder(c).WithViper(v)
+
+ for i := 0; i < 20; i++ {
+ b.WithContent(fmt.Sprintf("page%d.md", i), `---
+title: "Page"
+---
+`)
+ }
+
+ for i := 0; i < 5; i++ {
+ b.WithContent(fmt.Sprintf("blog/page%d.md", i), `---
+title: "Page"
+tags: ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
+---
+`)
+ }
+
+ for i := 0; i < 3; i++ {
+ b.WithContent(fmt.Sprintf("docs/page%d.md", i), `---
+title: "Page"
+---
+`)
+ }
+
+ b.WithTemplates("index.html", `
+mainSections: {{ .Site.Params.mainSections }}
+
+{{ range (where .Site.RegularPages "Type" "in" .Site.Params.mainSections) }}
+Main section page: {{ .RelPermalink }}
+{{ end }}
+`)
+
+ b.Build(BuildCfg{})
+
+ if paramSet {
+ b.AssertFileContent("public/index.html", "mainSections: [a1 a2]")
+ } else {
+ b.AssertFileContent("public/index.html", "mainSections: [blog]", "Main section page: /blog/page3/")
+ }
+
+ })
+ }
+}
+
// Issue #1176
func TestSectionNaming(t *testing.T) {
for _, canonify := range []bool{true, false} {