Add site-wide/per-page [blackfriday] extensions option

This commit is contained in:
Naoya Inada
2015-01-25 20:08:02 +09:00
committed by bep
parent 39b2cdece0
commit 407e80a9ab
7 changed files with 126 additions and 59 deletions

View File

@@ -17,16 +17,12 @@ import (
"bytes"
"errors"
"fmt"
"github.com/spf13/hugo/helpers"
"github.com/spf13/hugo/parser"
"reflect"
"github.com/spf13/cast"
"github.com/spf13/hugo/hugofs"
"github.com/spf13/hugo/source"
"github.com/spf13/hugo/tpl"
jww "github.com/spf13/jwalterweatherman"
"github.com/spf13/viper"
"github.com/mitchellh/mapstructure"
"github.com/spf13/hugo/helpers"
"github.com/spf13/hugo/parser"
"html/template"
"io"
"net/url"
@@ -35,6 +31,13 @@ import (
"strings"
"sync"
"time"
"github.com/spf13/cast"
"github.com/spf13/hugo/hugofs"
"github.com/spf13/hugo/source"
"github.com/spf13/hugo/tpl"
jww "github.com/spf13/jwalterweatherman"
"github.com/spf13/viper"
)
type Page struct {
@@ -52,17 +55,17 @@ type Page struct {
Tmpl tpl.Template
Markup string
extension string
contentType string
renderable bool
layout string
linkTitle string
frontmatter []byte
rawContent []byte
contentShortCodes map[string]string
plain string // TODO should be []byte
renderingConfigFlags map[string]bool
renderingConfigFlagsInit sync.Once
extension string
contentType string
renderable bool
layout string
linkTitle string
frontmatter []byte
rawContent []byte
contentShortCodes map[string]string
plain string // TODO should be []byte
renderingConfig *helpers.Blackfriday
renderingConfigInit sync.Once
PageMeta
Source
Position
@@ -182,37 +185,33 @@ func (p *Page) setSummary() {
func (p *Page) renderBytes(content []byte) []byte {
return helpers.RenderBytes(
helpers.RenderingContext{Content: content, PageFmt: p.guessMarkupType(),
DocumentId: p.UniqueId(), ConfigFlags: p.getRenderingConfigFlags()})
DocumentId: p.UniqueId(), Config: p.getRenderingConfig()})
}
func (p *Page) renderContent(content []byte) []byte {
return helpers.RenderBytesWithTOC(helpers.RenderingContext{Content: content, PageFmt: p.guessMarkupType(),
DocumentId: p.UniqueId(), ConfigFlags: p.getRenderingConfigFlags()})
DocumentId: p.UniqueId(), Config: p.getRenderingConfig()})
}
func (p *Page) getRenderingConfigFlags() map[string]bool {
p.renderingConfigFlagsInit.Do(func() {
p.renderingConfigFlags = make(map[string]bool)
func (p *Page) getRenderingConfig() *helpers.Blackfriday {
p.renderingConfigInit.Do(func() {
pageParam := p.GetParam("blackfriday")
siteParam := viper.GetStringMap("blackfriday")
p.renderingConfigFlags = cast.ToStringMapBool(siteParam)
if pageParam != nil {
pageFlags := cast.ToStringMapBool(pageParam)
for key, value := range pageFlags {
p.renderingConfigFlags[key] = value
pageConfig := cast.ToStringMap(pageParam)
for key, value := range pageConfig {
siteParam[key] = value
}
}
p.renderingConfig = new(helpers.Blackfriday)
if err := mapstructure.Decode(siteParam, p.renderingConfig); err != nil {
jww.FATAL.Printf("Failed to get rendering config for %s:\n%s", p.BaseFileName(), err.Error())
}
})
return p.renderingConfigFlags
}
func (p *Page) isRenderingFlagEnabled(flag string) bool {
return p.getRenderingConfigFlags()[flag]
return p.renderingConfig
}
func newPage(filename string) *Page {