diff options
author | Marek Janda <nyx@nyx.cz> | 2015-11-03 20:09:34 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2015-11-23 17:35:36 +0100 |
commit | 5838420aa1f5dfb6aa73479caa60467cc27dee82 (patch) | |
tree | e68e0daad3e4c9cce0609ce0f5d02e98ddc16083 /helpers | |
parent | fde47c5eb9435083cc492b8648517b374eb60c6b (diff) |
Move blackfriday site-wide config loading to NewBlackFriday()
Diffstat (limited to 'helpers')
-rw-r--r-- | helpers/content.go | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/helpers/content.go b/helpers/content.go index b42efaefe..157fbad5c 100644 --- a/helpers/content.go +++ b/helpers/content.go @@ -24,7 +24,9 @@ import ( "unicode/utf8" "github.com/miekg/mmark" + "github.com/mitchellh/mapstructure" "github.com/russross/blackfriday" + "github.com/spf13/cast" bp "github.com/spf13/hugo/bufferpool" jww "github.com/spf13/jwalterweatherman" "github.com/spf13/viper" @@ -52,17 +54,33 @@ type Blackfriday struct { ExtensionsMask []string } -// NewBlackfriday creates a new Blackfriday with some sane defaults. +// NewBlackfriday creates a new Blackfriday filled with site config or some sane defaults func NewBlackfriday() *Blackfriday { - return &Blackfriday{ - Smartypants: true, - AngledQuotes: false, - Fractions: true, - HrefTargetBlank: false, - SmartDashes: true, - LatexDashes: true, - PlainIDAnchors: false, + combinedParam := map[string]interface{}{ + "smartypants": true, + "angledQuotes": false, + "fractions": true, + "hrefTargetBlank": false, + "smartDashes": true, + "latexDashes": true, + "plainIDAnchors": false, + } + + siteParam := viper.GetStringMap("blackfriday") + if siteParam != nil { + siteConfig := cast.ToStringMap(siteParam) + + for key, value := range siteConfig { + combinedParam[key] = value + } + } + + combinedConfig := &Blackfriday{} + if err := mapstructure.Decode(combinedParam, combinedConfig); err != nil { + jww.FATAL.Printf("Failed to get site rendering config\n%s", err.Error()) } + + return combinedConfig } var blackfridayExtensionMap = map[string]int{ |