hugo

Unnamed repository; edit this file 'description' to name the repository.

git clone git://git.shimmy1996.com/hugo.git
commit 402f6788ee955ad2aace84e8fba1625db7b356d9
parent 3decf4a327157e98d3da3502b6d777de63437c39
Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date:   Mon, 23 Apr 2018 08:41:19 +0200

hugolib: Add .Page.BundleType

I eturn either:

1. leaf
2. branch
3. empty string

The above sits well with constructs like:

```
{{ with .BundleType }}
// Now we know it is a bundle
{{ end }}
```

Fixes #4662

Diffstat:
Mhugolib/page.go | 20++++++++++++++++++++
Mhugolib/page_bundler_test.go | 7++++++-
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/hugolib/page.go b/hugolib/page.go
@@ -451,6 +451,26 @@ func (p *Page) IsPage() bool {
 	return p.Kind == KindPage
 }
 
+// BundleType returns the bundle type: "leaf", "branch" or an empty string if it is none.
+// See https://gohugo.io/content-management/page-bundles/
+func (p *Page) BundleType() string {
+	if p.IsNode() {
+		return "branch"
+	}
+
+	var source interface{} = p.Source.File
+	if fi, ok := source.(*fileInfo); ok {
+		switch fi.bundleTp {
+		case bundleBranch:
+			return "branch"
+		case bundleLeaf:
+			return "leaf"
+		}
+	}
+
+	return ""
+}
+
 type Source struct {
 	Frontmatter []byte
 	Content     []byte
diff --git a/hugolib/page_bundler_test.go b/hugolib/page_bundler_test.go
@@ -82,6 +82,7 @@ func TestPageBundlerSiteRegular(t *testing.T) {
 				assert.Len(s.RegularPages, 8)
 
 				singlePage := s.getPage(KindPage, "a/1.md")
+				assert.Equal("", singlePage.BundleType())
 
 				assert.NotNil(singlePage)
 				assert.Equal(singlePage, s.getPage("page", "a/1"))
@@ -105,8 +106,12 @@ func TestPageBundlerSiteRegular(t *testing.T) {
 
 				leafBundle1 := s.getPage(KindPage, "b/my-bundle/index.md")
 				assert.NotNil(leafBundle1)
+				assert.Equal("leaf", leafBundle1.BundleType())
 				assert.Equal("b", leafBundle1.Section())
-				assert.NotNil(s.getPage(KindSection, "b"))
+				sectionB := s.getPage(KindSection, "b")
+				assert.NotNil(sectionB)
+				home, _ := s.Info.Home()
+				assert.Equal("branch", home.BundleType())
 
 				// This is a root bundle and should live in the "home section"
 				// See https://github.com/gohugoio/hugo/issues/4332