From ef7d14a2418e62e6a2fdde41c636f7c1b9300a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Fri, 28 Jan 2022 09:45:11 +0100 Subject: [PATCH] Fix erroneous warning with .Page.RenderString on a page without a backing file Fixes #9433 --- hugolib/content_render_hooks_test.go | 13 +++++++++++++ hugolib/page__meta.go | 6 +++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/hugolib/content_render_hooks_test.go b/hugolib/content_render_hooks_test.go index f1c27d511..edfeaa82a 100644 --- a/hugolib/content_render_hooks_test.go +++ b/hugolib/content_render_hooks_test.go @@ -18,6 +18,7 @@ import ( "testing" qt "github.com/frankban/quicktest" + "github.com/gohugoio/hugo/common/loggers" ) func TestRenderHookEditNestedPartial(t *testing.T) { @@ -484,3 +485,15 @@ func TestRenderStringOnListPage(t *testing.T) { b.AssertFileContent("public/"+filename, `Hello`) } } + +// Issue 9433 +func TestRenderStringOnPageNotBackedByAFile(t *testing.T) { + t.Parallel() + logger := loggers.NewWarningLogger() + b := newTestSitesBuilder(t).WithLogger(logger).WithConfigFile("toml", ` +disableKinds = ["page", "section", "taxonomy", "term"] +`) + b.WithTemplates("index.html", `{{ .RenderString "**Hello**" }}`).WithContent("p1.md", "") + b.BuildE(BuildCfg{}) + b.Assert(int(logger.LogCounters().WarnCounter.Count()), qt.Equals, 0) +} diff --git a/hugolib/page__meta.go b/hugolib/page__meta.go index 5581b6ebd..dcbf1a606 100644 --- a/hugolib/page__meta.go +++ b/hugolib/page__meta.go @@ -768,16 +768,20 @@ func (p *pageMeta) newContentConverter(ps *pageState, markup string, renderingCo var id string var filename string + var path string if !p.f.IsZero() { id = p.f.UniqueID() filename = p.f.Filename() + path = p.f.Path() + } else { + path = p.Pathc() } cpp, err := cp.New( converter.DocumentContext{ Document: newPageForRenderHook(ps), DocumentID: id, - DocumentName: p.File().Path(), + DocumentName: path, Filename: filename, ConfigOverrides: renderingConfigOverrides, },