mirror of
https://github.com/gohugoio/hugo.git
synced 2025-02-17 03:34:50 +00:00
Revert "Create template clone for late template execution"
This reverts commit 93b04e67f6
.
This commit is contained in:
parent
93b04e67f6
commit
6b922750f3
2 changed files with 1 additions and 26 deletions
|
@ -595,7 +595,6 @@ func (s *Site) prepTemplates() {
|
||||||
if s.hasTheme() {
|
if s.hasTheme() {
|
||||||
s.Tmpl.LoadTemplatesWithPrefix(s.absThemeDir()+"/layouts", "theme")
|
s.Tmpl.LoadTemplatesWithPrefix(s.absThemeDir()+"/layouts", "theme")
|
||||||
}
|
}
|
||||||
s.Tmpl.MarkReady()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) addTemplate(name, data string) error {
|
func (s *Site) addTemplate(name, data string) error {
|
||||||
|
@ -1367,15 +1366,11 @@ func (s *Site) RenderPages() error {
|
||||||
// this cannot be fanned out to multiple Go routines
|
// this cannot be fanned out to multiple Go routines
|
||||||
// See issue #1601
|
// See issue #1601
|
||||||
// TODO(bep): Check the IsRenderable logic.
|
// TODO(bep): Check the IsRenderable logic.
|
||||||
|
|
||||||
// Issue #1879
|
|
||||||
templ := s.Tmpl.Clone()
|
|
||||||
|
|
||||||
for _, p := range s.Pages {
|
for _, p := range s.Pages {
|
||||||
var layouts []string
|
var layouts []string
|
||||||
if !p.IsRenderable() {
|
if !p.IsRenderable() {
|
||||||
self := "__" + p.TargetPath()
|
self := "__" + p.TargetPath()
|
||||||
_, err := templ.New(self).Parse(string(p.Content))
|
_, err := s.Tmpl.New(self).Parse(string(p.Content))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
results <- err
|
results <- err
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -37,14 +37,12 @@ type Template interface {
|
||||||
Lookup(name string) *template.Template
|
Lookup(name string) *template.Template
|
||||||
Templates() []*template.Template
|
Templates() []*template.Template
|
||||||
New(name string) *template.Template
|
New(name string) *template.Template
|
||||||
Clone() *template.Template
|
|
||||||
LoadTemplates(absPath string)
|
LoadTemplates(absPath string)
|
||||||
LoadTemplatesWithPrefix(absPath, prefix string)
|
LoadTemplatesWithPrefix(absPath, prefix string)
|
||||||
AddTemplate(name, tpl string) error
|
AddTemplate(name, tpl string) error
|
||||||
AddAceTemplate(name, basePath, innerPath string, baseContent, innerContent []byte) error
|
AddAceTemplate(name, basePath, innerPath string, baseContent, innerContent []byte) error
|
||||||
AddInternalTemplate(prefix, name, tpl string) error
|
AddInternalTemplate(prefix, name, tpl string) error
|
||||||
AddInternalShortcode(name, tpl string) error
|
AddInternalShortcode(name, tpl string) error
|
||||||
MarkReady()
|
|
||||||
PrintErrors()
|
PrintErrors()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,8 +53,6 @@ type templateErr struct {
|
||||||
|
|
||||||
type GoHTMLTemplate struct {
|
type GoHTMLTemplate struct {
|
||||||
template.Template
|
template.Template
|
||||||
clone *template.Template
|
|
||||||
ready bool
|
|
||||||
errors []*templateErr
|
errors []*templateErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,22 +140,6 @@ func (t *GoHTMLTemplate) LoadEmbedded() {
|
||||||
t.EmbedTemplates()
|
t.EmbedTemplates()
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarkReady marks the template as "ready for execution". No changes allowed
|
|
||||||
// after this is set.
|
|
||||||
func (t *GoHTMLTemplate) MarkReady() {
|
|
||||||
t.clone = template.Must(t.Template.Clone())
|
|
||||||
t.ready = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Since Go 1.6, the template cannot change once executed. So we have to create
|
|
||||||
// a clone and work with that in some rare cases.
|
|
||||||
func (t *GoHTMLTemplate) Clone() *template.Template {
|
|
||||||
if !t.ready {
|
|
||||||
panic("template clone called too early")
|
|
||||||
}
|
|
||||||
return template.Must(t.clone.Clone())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *GoHTMLTemplate) AddInternalTemplate(prefix, name, tpl string) error {
|
func (t *GoHTMLTemplate) AddInternalTemplate(prefix, name, tpl string) error {
|
||||||
if prefix != "" {
|
if prefix != "" {
|
||||||
return t.AddTemplate("_internal/"+prefix+"/"+name, tpl)
|
return t.AddTemplate("_internal/"+prefix+"/"+name, tpl)
|
||||||
|
|
Loading…
Reference in a new issue