mirror of
https://github.com/gohugoio/hugo.git
synced 2025-03-22 22:04:19 +00:00
Cache the page's rendering context flags
This map can potentially be used many times for a given page, and altough the cost of re-creating the map should be minimal, caching it is simple -- and could save some GC and CPU cycles.
This commit is contained in:
parent
19c52ab0b5
commit
c8f8f48e96
1 changed files with 25 additions and 19 deletions
|
@ -32,6 +32,7 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -50,15 +51,17 @@ type Page struct {
|
||||||
Tmpl tpl.Template
|
Tmpl tpl.Template
|
||||||
Markup string
|
Markup string
|
||||||
|
|
||||||
extension string
|
extension string
|
||||||
contentType string
|
contentType string
|
||||||
renderable bool
|
renderable bool
|
||||||
layout string
|
layout string
|
||||||
linkTitle string
|
linkTitle string
|
||||||
frontmatter []byte
|
frontmatter []byte
|
||||||
rawContent []byte
|
rawContent []byte
|
||||||
contentShortCodes map[string]string
|
contentShortCodes map[string]string
|
||||||
plain string // TODO should be []byte
|
plain string // TODO should be []byte
|
||||||
|
renderingConfigFlags map[string]bool
|
||||||
|
renderingConfigFlagsInit sync.Once
|
||||||
PageMeta
|
PageMeta
|
||||||
Source
|
Source
|
||||||
Position
|
Position
|
||||||
|
@ -187,21 +190,24 @@ func (p *Page) renderContent(content []byte) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Page) getRenderingConfigFlags() map[string]bool {
|
func (p *Page) getRenderingConfigFlags() map[string]bool {
|
||||||
flags := make(map[string]bool)
|
|
||||||
|
|
||||||
pageParam := p.GetParam("blackfriday")
|
p.renderingConfigFlagsInit.Do(func() {
|
||||||
siteParam := viper.GetStringMap("blackfriday")
|
p.renderingConfigFlags = make(map[string]bool)
|
||||||
|
|
||||||
flags = cast.ToStringMapBool(siteParam)
|
pageParam := p.GetParam("blackfriday")
|
||||||
|
siteParam := viper.GetStringMap("blackfriday")
|
||||||
|
|
||||||
if pageParam != nil {
|
p.renderingConfigFlags = cast.ToStringMapBool(siteParam)
|
||||||
pageFlags := cast.ToStringMapBool(pageParam)
|
|
||||||
for key, value := range pageFlags {
|
if pageParam != nil {
|
||||||
flags[key] = value
|
pageFlags := cast.ToStringMapBool(pageParam)
|
||||||
|
for key, value := range pageFlags {
|
||||||
|
p.renderingConfigFlags[key] = value
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
return flags
|
return p.renderingConfigFlags
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Page) isRenderingFlagEnabled(flag string) bool {
|
func (p *Page) isRenderingFlagEnabled(flag string) bool {
|
||||||
|
|
Loading…
Reference in a new issue