mirror of
https://github.com/gohugoio/hugo.git
synced 2024-05-11 05:54:58 +00:00
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
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user