From b0d850321e58a052ead25f7014b7851f63497601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Fri, 28 Feb 2020 12:39:58 +0100 Subject: [PATCH] Fix rebuild logic when editing template using a base template We have been doing too much work in that case. Fixes #6968 --- hugolib/hugo_sites_rebuild_test.go | 25 +++++++++++++++++++++++++ tpl/tplimpl/template.go | 6 ++++++ 2 files changed, 31 insertions(+) diff --git a/hugolib/hugo_sites_rebuild_test.go b/hugolib/hugo_sites_rebuild_test.go index eca6c730b..1f0b1b5d9 100644 --- a/hugolib/hugo_sites_rebuild_test.go +++ b/hugolib/hugo_sites_rebuild_test.go @@ -15,6 +15,8 @@ package hugolib import ( "testing" + + qt "github.com/frankban/quicktest" ) func TestSitesRebuild(t *testing.T) { @@ -142,6 +144,29 @@ Data Inline: Rules!`) }) + // https://github.com/gohugoio/hugo/issues/6968 + t.Run("Edit single.html with base", func(t *testing.T) { + b := newTestSitesBuilder(t).Running() + + b.WithTemplates( + "_default/single.html", `{{ define "main" }}Single{{ end }}`, + "_default/baseof.html", `Base: {{ block "main" .}}Block{{ end }}`, + ) + + b.WithContent("p1.md", "---\ntitle: Page\n---") + + b.Build(BuildCfg{}) + + b.EditFiles("layouts/_default/single.html", `Single Edit: {{ define "main" }}Single{{ end }}`) + + counters := &testCounters{} + + b.Build(BuildCfg{testCounters: counters}) + + b.Assert(int(counters.contentRenderCounter), qt.Equals, 0) + + }) + t.Run("Page.Render, edit baseof", func(t *testing.T) { b := createSiteBuilder(t) diff --git a/tpl/tplimpl/template.go b/tpl/tplimpl/template.go index 457a5cb92..b6313e1e5 100644 --- a/tpl/tplimpl/template.go +++ b/tpl/tplimpl/template.go @@ -383,9 +383,15 @@ func (t *templateHandler) LookupVariant(name string, variants tpl.TemplateVarian } func (t *templateHandler) HasTemplate(name string) bool { + if _, found := t.baseof[name]; found { return true } + + if _, found := t.needsBaseof[name]; found { + return true + } + _, found := t.Lookup(name) return found }