Skip to content

Commit

Permalink
hugolib: Prevent decoding pageParam in common cases
Browse files Browse the repository at this point in the history
  • Loading branch information
n10v authored and bep committed Apr 22, 2017
1 parent 6498d73 commit e98f885
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions hugolib/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,15 +606,20 @@ func (p *Page) renderContent(content []byte) []byte {
}

func (p *Page) getRenderingConfig() *helpers.Blackfriday {

p.renderingConfigInit.Do(func() {
pageParam := cast.ToStringMap(p.GetParam("blackfriday"))
p.renderingConfig = p.s.ContentSpec.NewBlackfriday()

if p.Language() == nil {
panic(fmt.Sprintf("nil language for %s with source lang %s", p.BaseFileName(), p.lang))
}
p.renderingConfig = p.s.ContentSpec.NewBlackfriday()

if err := mapstructure.Decode(pageParam, p.renderingConfig); err != nil {
bfParam := p.GetParam("blackfriday")
if bfParam == nil {
return
}

pageParam := cast.ToStringMap(bfParam)
if err := mapstructure.Decode(pageParam, &p.renderingConfig); err != nil {
p.s.Log.FATAL.Printf("Failed to get rendering config for %s:\n%s", p.BaseFileName(), err.Error())
}

Expand Down

0 comments on commit e98f885

Please sign in to comment.