summaryrefslogtreecommitdiffstats
path: root/tpl
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-02-21 13:55:08 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-02-21 13:56:20 +0100
commit2cbdd65330a727ae172b11b4b9dc96f675e1bb19 (patch)
tree79ab97c8642aa41dbaf29e15ee432c4e4018bf35 /tpl
parent4e77c8717b18b8b54f4e56cb305da6cf3bc26be7 (diff)
tpl, hugolib: Fix live-reload of non-renderable content pages
Fixes #3062
Diffstat (limited to 'tpl')
-rw-r--r--tpl/template.go1
-rw-r--r--tpl/tplimpl/template.go16
2 files changed, 15 insertions, 2 deletions
diff --git a/tpl/template.go b/tpl/template.go
index aaf7fc8c7..b94fc3242 100644
--- a/tpl/template.go
+++ b/tpl/template.go
@@ -13,6 +13,7 @@ type Template interface {
Templates() []*template.Template
New(name string) *template.Template
GetClone() *template.Template
+ RebuildClone() *template.Template
LoadTemplates(absPath string)
LoadTemplatesWithPrefix(absPath, prefix string)
AddTemplate(name, tpl string) error
diff --git a/tpl/tplimpl/template.go b/tpl/tplimpl/template.go
index cf1fc5620..012319104 100644
--- a/tpl/tplimpl/template.go
+++ b/tpl/tplimpl/template.go
@@ -44,7 +44,12 @@ type templateErr struct {
type GoHTMLTemplate struct {
*template.Template
- clone *template.Template
+ // This looks, and is, strange.
+ // The clone is used by non-renderable content pages, and these need to be
+ // re-parsed on content change, and to avoid the
+ // "cannot Parse after Execute" error, we need to re-clone it from the original clone.
+ clone *template.Template
+ cloneClone *template.Template
// a separate storage for the overlays created from cloned master templates.
// note: No mutex protection, so we add these in one Go routine, then just read.
@@ -66,7 +71,6 @@ var DefaultTemplateProvider *TemplateProvider
// Update updates the Hugo Template System in the provided Deps.
// with all the additional features, templates & functions
func (*TemplateProvider) Update(deps *deps.Deps) error {
- // TODO(bep) check that this isn't called too many times.
tmpl := &GoHTMLTemplate{
Template: template.New(""),
overlays: make(map[string]*template.Template),
@@ -229,6 +233,11 @@ func (t *GoHTMLTemplate) GetClone() *template.Template {
return t.clone
}
+func (t *GoHTMLTemplate) RebuildClone() *template.Template {
+ t.clone = template.Must(t.cloneClone.Clone())
+ return t.clone
+}
+
func (t *GoHTMLTemplate) LoadEmbedded() {
t.EmbedShortcodes()
t.EmbedTemplates()
@@ -236,9 +245,12 @@ func (t *GoHTMLTemplate) LoadEmbedded() {
// MarkReady marks the template as "ready for execution". No changes allowed
// after this is set.
+// TODO(bep) if this proves to be resource heavy, we could detect
+// earlier if we really need this, or make it lazy.
func (t *GoHTMLTemplate) MarkReady() {
if t.clone == nil {
t.clone = template.Must(t.Template.Clone())
+ t.cloneClone = template.Must(t.clone.Clone())
}
}