mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
Fix panic with markdownify/RenderString with shortcode on Page with no content file
Fixes #9959
This commit is contained in:
parent
4daac654d9
commit
212d9e3017
6 changed files with 35 additions and 6 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -33,8 +33,6 @@ type pageContent struct {
|
|||
|
||||
cmap *pageContentMap
|
||||
|
||||
shortcodeState *shortcodeHandler
|
||||
|
||||
source rawPageContent
|
||||
}
|
||||
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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
|
||||
`)
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue