Skip to content

Commit

Permalink
Fix erroneous warning with .Page.RenderString on a page without a bac…
Browse files Browse the repository at this point in the history
…king file

Fixes #9433
  • Loading branch information
bep committed Jan 28, 2022
1 parent c05c99f commit ef7d14a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
13 changes: 13 additions & 0 deletions hugolib/content_render_hooks_test.go
Expand Up @@ -18,6 +18,7 @@ import (
"testing"

qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/common/loggers"
)

func TestRenderHookEditNestedPartial(t *testing.T) {
Expand Down Expand Up @@ -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)
}
6 changes: 5 additions & 1 deletion hugolib/page__meta.go
Expand Up @@ -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,
},
Expand Down

0 comments on commit ef7d14a

Please sign in to comment.