Skip to content

Commit

Permalink
hugolib: Allow index.md inside bundles
Browse files Browse the repository at this point in the history
Fixes #6208
  • Loading branch information
bep committed Aug 17, 2019
1 parent 18836a7 commit 4b4bdcf
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
42 changes: 42 additions & 0 deletions hugolib/pagebundler_test.go
Expand Up @@ -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|
`)

}
5 changes: 5 additions & 0 deletions hugolib/pages_capture.go
Expand Up @@ -370,6 +370,11 @@ func (c *pagesCollector) addToBundle(info hugofs.FileMetaInfo, btyp bundleDirTyp
lang := c.getLang(info) lang := c.getLang(info)
bundle := getBundle(lang) bundle := getBundle(lang)
isBundleHeader := c.isBundleHeader(info) 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() classifier := info.Meta().Classifier()
isContent := classifier == files.ContentClassContent isContent := classifier == files.ContentClassContent
if bundle == nil { if bundle == nil {
Expand Down

0 comments on commit 4b4bdcf

Please sign in to comment.