mirror of
https://github.com/gohugoio/hugo.git
synced 2024-07-05 00:32:03 +00:00
Move blackfriday site-wide config loading to NewBlackFriday()
This commit is contained in:
parent
fde47c5eb9
commit
5838420aa1
|
@ -24,7 +24,9 @@ import (
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/miekg/mmark"
|
"github.com/miekg/mmark"
|
||||||
|
"github.com/mitchellh/mapstructure"
|
||||||
"github.com/russross/blackfriday"
|
"github.com/russross/blackfriday"
|
||||||
|
"github.com/spf13/cast"
|
||||||
bp "github.com/spf13/hugo/bufferpool"
|
bp "github.com/spf13/hugo/bufferpool"
|
||||||
jww "github.com/spf13/jwalterweatherman"
|
jww "github.com/spf13/jwalterweatherman"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
@ -52,17 +54,33 @@ type Blackfriday struct {
|
||||||
ExtensionsMask []string
|
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 {
|
func NewBlackfriday() *Blackfriday {
|
||||||
return &Blackfriday{
|
combinedParam := map[string]interface{}{
|
||||||
Smartypants: true,
|
"smartypants": true,
|
||||||
AngledQuotes: false,
|
"angledQuotes": false,
|
||||||
Fractions: true,
|
"fractions": true,
|
||||||
HrefTargetBlank: false,
|
"hrefTargetBlank": false,
|
||||||
SmartDashes: true,
|
"smartDashes": true,
|
||||||
LatexDashes: true,
|
"latexDashes": true,
|
||||||
PlainIDAnchors: false,
|
"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{
|
var blackfridayExtensionMap = map[string]int{
|
||||||
|
|
|
@ -246,26 +246,10 @@ func (p *Page) renderContent(content []byte) []byte {
|
||||||
func (p *Page) getRenderingConfig() *helpers.Blackfriday {
|
func (p *Page) getRenderingConfig() *helpers.Blackfriday {
|
||||||
|
|
||||||
p.renderingConfigInit.Do(func() {
|
p.renderingConfigInit.Do(func() {
|
||||||
pageParam := p.GetParam("blackfriday")
|
pageParam := cast.ToStringMap(p.GetParam("blackfriday"))
|
||||||
siteParam := viper.GetStringMap("blackfriday")
|
|
||||||
|
|
||||||
combinedParam := siteParam
|
|
||||||
|
|
||||||
if pageParam != nil {
|
|
||||||
combinedParam = make(map[string]interface{})
|
|
||||||
|
|
||||||
for k, v := range siteParam {
|
|
||||||
combinedParam[k] = v
|
|
||||||
}
|
|
||||||
|
|
||||||
pageConfig := cast.ToStringMap(pageParam)
|
|
||||||
|
|
||||||
for key, value := range pageConfig {
|
|
||||||
combinedParam[key] = value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
p.renderingConfig = helpers.NewBlackfriday()
|
p.renderingConfig = helpers.NewBlackfriday()
|
||||||
if err := mapstructure.Decode(combinedParam, p.renderingConfig); err != nil {
|
if err := mapstructure.Decode(pageParam, p.renderingConfig); err != nil {
|
||||||
jww.FATAL.Printf("Failed to get rendering config for %s:\n%s", p.BaseFileName(), err.Error())
|
jww.FATAL.Printf("Failed to get rendering config for %s:\n%s", p.BaseFileName(), err.Error())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue