diff options
-rw-r--r-- | hugolib/content_map_page.go | 2 | ||||
-rw-r--r-- | hugolib/page__common.go | 3 | ||||
-rw-r--r-- | hugolib/page__content.go | 2 | ||||
-rw-r--r-- | hugolib/page__new.go | 2 | ||||
-rw-r--r-- | hugolib/page__per_output.go | 2 | ||||
-rw-r--r-- | hugolib/renderstring_test.go | 30 |
6 files changed, 35 insertions, 6 deletions
diff --git a/hugolib/content_map_page.go b/hugolib/content_map_page.go index c6522809e..7e6b6e670 100644 --- a/hugolib/content_map_page.go +++ b/hugolib/content_map_page.go @@ -163,8 +163,6 @@ func (m *pageMap) newPageFromContentNode(n *contentNode, parentBucket *pagesMapB }, } - ps.shortcodeState = newShortcodeHandler(ps, ps.s) - if err := ps.mapContent(parentBucket, metaProvider); err != nil { return nil, ps.wrapError(err) } diff --git a/hugolib/page__common.go b/hugolib/page__common.go index e55bb7e25..59f0bc776 100644 --- a/hugolib/page__common.go +++ b/hugolib/page__common.go @@ -102,6 +102,9 @@ type pageCommon struct { // The parsed page content. pageContent + // Keeps track of the shortcodes on a page. + shortcodeState *shortcodeHandler + // Set if feature enabled and this is in a Git repo. gitInfo *gitmap.GitInfo codeowners []string diff --git a/hugolib/page__content.go b/hugolib/page__content.go index 587188454..bf69fafcd 100644 --- a/hugolib/page__content.go +++ b/hugolib/page__content.go @@ -33,8 +33,6 @@ type pageContent struct { cmap *pageContentMap - shortcodeState *shortcodeHandler - source rawPageContent } diff --git a/hugolib/page__new.go b/hugolib/page__new.go index 897c0281b..e52b9476b 100644 --- a/hugolib/page__new.go +++ b/hugolib/page__new.go @@ -66,6 +66,8 @@ func newPageBase(metaProvider *pageMeta) (*pageState, error) { }, } + ps.shortcodeState = newShortcodeHandler(ps, ps.s) + siteAdapter := pageSiteAdapter{s: s, p: ps} ps.pageMenus = &pageMenus{p: ps} diff --git a/hugolib/page__per_output.go b/hugolib/page__per_output.go index 2bf16dd9e..e69d32e27 100644 --- a/hugolib/page__per_output.go +++ b/hugolib/page__per_output.go @@ -25,7 +25,6 @@ import ( "errors" - "github.com/gohugoio/hugo/common/herrors" "github.com/gohugoio/hugo/common/text" "github.com/gohugoio/hugo/common/types/hstring" "github.com/gohugoio/hugo/identity" @@ -334,7 +333,6 @@ func (p *pageContentOutput) WordCount() int { } func (p *pageContentOutput) RenderString(args ...any) (template.HTML, error) { - defer herrors.Recover() if len(args) < 1 || len(args) > 2 { return "", errors.New("want 1 or 2 arguments") } diff --git a/hugolib/renderstring_test.go b/hugolib/renderstring_test.go index d2f453c33..1be0cdffb 100644 --- a/hugolib/renderstring_test.go +++ b/hugolib/renderstring_test.go @@ -158,5 +158,35 @@ Page Type: *hugolib.pageForShortcode`, ) }) +} + +// Issue 9959 +func TestRenderStringWithShortcodeInPageWithNoContentFile(t *testing.T) { + t.Parallel() + + files := ` +-- config.toml -- +-- layouts/shortcodes/myshort.html -- +Page Kind: {{ .Page.Kind }} +-- layouts/index.html -- +Short: {{ .RenderString "{{< myshort >}}" }} +Has myshort: {{ .HasShortcode "myshort" }} +Has other: {{ .HasShortcode "other" }} + + ` + + b := NewIntegrationTestBuilder( + IntegrationTestConfig{ + T: t, + TxtarString: files, + }, + ).Build() + + b.AssertFileContent("public/index.html", + ` +Page Kind: home +Has myshort: true +Has other: false +`) } |