mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-28 22:19:59 +02:00
Add IsRenderable to Page
As pages are read from the target, they will be assessed if they should be rendered or not. The logic for IsRenderable is in the parser/page.go and looks for anything exception '<'.
This commit is contained in:
@@ -44,6 +44,7 @@ type Page struct {
|
||||
Aliases []string
|
||||
Tmpl bundle.Template
|
||||
Markup string
|
||||
renderable bool
|
||||
PageMeta
|
||||
File
|
||||
Position
|
||||
@@ -128,6 +129,10 @@ func StripHTML(s string) string {
|
||||
return output
|
||||
}
|
||||
|
||||
func (p *Page) IsRenderable() bool {
|
||||
return p.renderable
|
||||
}
|
||||
|
||||
func (p *Page) guessSection() {
|
||||
if p.Section == "" {
|
||||
x := strings.Split(p.FileName, "/")
|
||||
@@ -323,12 +328,15 @@ type frontmatterType struct {
|
||||
includeMark bool
|
||||
}
|
||||
|
||||
const YAML_DELIM = "---"
|
||||
const TOML_DELIM = "+++"
|
||||
|
||||
func (page *Page) detectFrontMatter(mark rune) (f *frontmatterType) {
|
||||
switch mark {
|
||||
case '-':
|
||||
return &frontmatterType{[]byte{'-', '-', '-'}, []byte{'-', '-', '-'}, page.handleYamlMetaData, false}
|
||||
return &frontmatterType{[]byte(YAML_DELIM), []byte(YAML_DELIM), page.handleYamlMetaData, false}
|
||||
case '+':
|
||||
return &frontmatterType{[]byte{'+', '+', '+'}, []byte{'+', '+', '+'}, page.handleTomlMetaData, false}
|
||||
return &frontmatterType{[]byte(TOML_DELIM), []byte(TOML_DELIM), page.handleTomlMetaData, false}
|
||||
case '{':
|
||||
return &frontmatterType{[]byte{'{'}, []byte{'}'}, page.handleJsonMetaData, true}
|
||||
default:
|
||||
@@ -359,18 +367,20 @@ func (page *Page) parse(reader io.Reader) error {
|
||||
return err
|
||||
}
|
||||
|
||||
front := p.FrontMatter()
|
||||
if len(front) == 0 {
|
||||
return errors.New("Unable to locate frontmatter")
|
||||
}
|
||||
fm := page.detectFrontMatter(rune(front[0]))
|
||||
meta, err := fm.parse(front)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
page.renderable = p.IsRenderable()
|
||||
|
||||
if err = page.update(meta); err != nil {
|
||||
return err
|
||||
front := p.FrontMatter()
|
||||
|
||||
if len(front) != 0 {
|
||||
fm := page.detectFrontMatter(rune(front[0]))
|
||||
meta, err := fm.parse(front)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = page.update(meta); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
switch page.Markup {
|
||||
|
Reference in New Issue
Block a user