hugolib: Allow index.md inside bundles
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 17 Aug 2019 14:22:24 +0000 (16:22 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 17 Aug 2019 16:50:16 +0000 (18:50 +0200)
Fixes #6208

hugolib/pagebundler_test.go
hugolib/pages_capture.go

index a12dd713eb0ef45b980de80b39d39ffcf845a3f5..4b3eef512e911a8f091b22d6bf516b46beb98731 100644 (file)
@@ -1176,3 +1176,45 @@ Num Pages: {{ len .Site.Pages }}
        )
 
 }
+
+// #6208
+func TestBundleIndexInSubFolder(t *testing.T) {
+       config := `
+baseURL = "https://example.com"
+
+`
+
+       const pageContent = `---
+title: %q
+---
+`
+       createPage := func(s string) string {
+               return fmt.Sprintf(pageContent, s)
+       }
+
+       b := newTestSitesBuilder(t).WithConfigFile("toml", config)
+       b.WithLogger(loggers.NewWarningLogger())
+
+       b.WithTemplates("_default/single.html", `{{ range .Resources }}
+{{ .ResourceType }}|{{ .Title }}|
+{{ end }}
+
+
+`)
+
+       b.WithContent("bundle/index.md", createPage("bundle index"))
+       b.WithContent("bundle/p1.md", createPage("bundle p1"))
+       b.WithContent("bundle/sub/p2.md", createPage("bundle sub p2"))
+       b.WithContent("bundle/sub/index.md", createPage("bundle sub index"))
+       b.WithContent("bundle/sub/data.json", "data")
+
+       b.Build(BuildCfg{})
+
+       b.AssertFileContent("public/bundle/index.html", `
+        json|sub/data.json|
+        page|bundle p1|
+        page|bundle sub index|
+        page|bundle sub p2|
+`)
+
+}
index f332e85a8687e2b745f3979faef7b72b947726c1..591b8e317551dcf53e36ca3cd6e076ddbe6ed719 100644 (file)
@@ -370,6 +370,11 @@ func (c *pagesCollector) addToBundle(info hugofs.FileMetaInfo, btyp bundleDirTyp
        lang := c.getLang(info)
        bundle := getBundle(lang)
        isBundleHeader := c.isBundleHeader(info)
+       if bundle != nil && isBundleHeader {
+               // index.md file inside a bundle, see issue 6208.
+               info.Meta()["classifier"] = files.ContentClassContent
+               isBundleHeader = false
+       }
        classifier := info.Meta().Classifier()
        isContent := classifier == files.ContentClassContent
        if bundle == nil {