mirror of
https://github.com/gohugoio/hugo.git
synced 2025-03-15 02:04:02 +00:00
tpl, hugolib: Fix live-reload of non-renderable content pages
Fixes #3062
This commit is contained in:
parent
4e77c8717b
commit
2cbdd65330
4 changed files with 23 additions and 2 deletions
|
@ -107,6 +107,13 @@ func (h *HugoSites) initRebuild(config *BuildCfg) error {
|
||||||
|
|
||||||
h.runMode.Watching = config.Watching
|
h.runMode.Watching = config.Watching
|
||||||
|
|
||||||
|
if config.whatChanged.source {
|
||||||
|
// This is for the non-renderable content pages (rarely used, I guess).
|
||||||
|
// We could maybe detect if this is really needed, but it should be
|
||||||
|
// pretty fast.
|
||||||
|
h.Tmpl.RebuildClone()
|
||||||
|
}
|
||||||
|
|
||||||
for _, s := range h.Sites {
|
for _, s := range h.Sites {
|
||||||
s.resetBuildState()
|
s.resetBuildState()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1571,6 +1571,7 @@ func (s *Site) resetBuildState() {
|
||||||
s.Info.paginationPageCount = 0
|
s.Info.paginationPageCount = 0
|
||||||
s.draftCount = 0
|
s.draftCount = 0
|
||||||
s.futureCount = 0
|
s.futureCount = 0
|
||||||
|
|
||||||
s.expiredCount = 0
|
s.expiredCount = 0
|
||||||
|
|
||||||
for _, p := range s.rawAllPages {
|
for _, p := range s.rawAllPages {
|
||||||
|
|
|
@ -13,6 +13,7 @@ type Template interface {
|
||||||
Templates() []*template.Template
|
Templates() []*template.Template
|
||||||
New(name string) *template.Template
|
New(name string) *template.Template
|
||||||
GetClone() *template.Template
|
GetClone() *template.Template
|
||||||
|
RebuildClone() *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
|
||||||
|
|
|
@ -44,7 +44,12 @@ type templateErr struct {
|
||||||
type GoHTMLTemplate struct {
|
type GoHTMLTemplate struct {
|
||||||
*template.Template
|
*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.
|
// 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.
|
// 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.
|
// Update updates the Hugo Template System in the provided Deps.
|
||||||
// with all the additional features, templates & functions
|
// with all the additional features, templates & functions
|
||||||
func (*TemplateProvider) Update(deps *deps.Deps) error {
|
func (*TemplateProvider) Update(deps *deps.Deps) error {
|
||||||
// TODO(bep) check that this isn't called too many times.
|
|
||||||
tmpl := &GoHTMLTemplate{
|
tmpl := &GoHTMLTemplate{
|
||||||
Template: template.New(""),
|
Template: template.New(""),
|
||||||
overlays: make(map[string]*template.Template),
|
overlays: make(map[string]*template.Template),
|
||||||
|
@ -229,6 +233,11 @@ func (t *GoHTMLTemplate) GetClone() *template.Template {
|
||||||
return t.clone
|
return t.clone
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *GoHTMLTemplate) RebuildClone() *template.Template {
|
||||||
|
t.clone = template.Must(t.cloneClone.Clone())
|
||||||
|
return t.clone
|
||||||
|
}
|
||||||
|
|
||||||
func (t *GoHTMLTemplate) LoadEmbedded() {
|
func (t *GoHTMLTemplate) LoadEmbedded() {
|
||||||
t.EmbedShortcodes()
|
t.EmbedShortcodes()
|
||||||
t.EmbedTemplates()
|
t.EmbedTemplates()
|
||||||
|
@ -236,9 +245,12 @@ func (t *GoHTMLTemplate) LoadEmbedded() {
|
||||||
|
|
||||||
// MarkReady marks the template as "ready for execution". No changes allowed
|
// MarkReady marks the template as "ready for execution". No changes allowed
|
||||||
// after this is set.
|
// 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() {
|
func (t *GoHTMLTemplate) MarkReady() {
|
||||||
if t.clone == nil {
|
if t.clone == nil {
|
||||||
t.clone = template.Must(t.Template.Clone())
|
t.clone = template.Must(t.Template.Clone())
|
||||||
|
t.cloneClone = template.Must(t.clone.Clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue