mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-24 21:56:05 +02:00
Add site-wide/per-page [blackfriday] extensions
option
This commit is contained in:
@@ -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 {
|
||||
|
Reference in New Issue
Block a user