Fix erroneous warning with .Page.RenderString on a page without a backing file
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 28 Jan 2022 08:45:11 +0000 (09:45 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 28 Jan 2022 16:35:49 +0000 (17:35 +0100)
Fixes #9433

hugolib/content_render_hooks_test.go
hugolib/page__meta.go

index f1c27d51191271d5d102db81d9f0af6439aef0f2..edfeaa82a81aea003cff4ab34191e2cab1c1d054 100644 (file)
@@ -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, `<strong>Hello</strong>`)
        }
 }
+
+// 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)
+}
index 5581b6ebd95bb160ac6fe46cdb28e3fa21604e8b..dcbf1a6061f0ebecf95212c95b53425fc1c51561 100644 (file)
@@ -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,
                },