diff options
author | Bjørn Erik Pedersen <[email protected]> | 2024-05-29 12:59:57 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2024-05-30 11:29:21 +0200 |
commit | 519f41dbd72d4b13208225ab5b28c6d98ecb07ba (patch) | |
tree | e1fd7fd1fff1ba6ddfe2aac4ff1616ca26dea201 /hugolib | |
parent | 7f3061723e3df064515fc57c183b06ed16f26b75 (diff) | |
download | hugo-519f41dbd72d4b13208225ab5b28c6d98ecb07ba.tar.gz hugo-519f41dbd72d4b13208225ab5b28c6d98ecb07ba.zip |
content adapter: Fix issue with content starting out with a shortcode
Fixes #12544
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/page__content.go | 18 | ||||
-rw-r--r-- | hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go | 25 |
2 files changed, 35 insertions, 8 deletions
diff --git a/hugolib/page__content.go b/hugolib/page__content.go index 1ef31f0f9..1119a8a95 100644 --- a/hugolib/page__content.go +++ b/hugolib/page__content.go @@ -57,14 +57,14 @@ type pageContentReplacement struct { func (m *pageMeta) parseFrontMatter(h *HugoSites, pid uint64) (*contentParseInfo, error) { var ( - sourceKey string - openSource hugio.OpenReadSeekCloser - hasContent = m.pageConfig.IsFromContentAdapter + sourceKey string + openSource hugio.OpenReadSeekCloser + isFromContentAdapter = m.pageConfig.IsFromContentAdapter ) - if m.f != nil && !hasContent { + if m.f != nil && !isFromContentAdapter { sourceKey = filepath.ToSlash(m.f.Filename()) - if !hasContent { + if !isFromContentAdapter { meta := m.f.FileInfo().Meta() openSource = func() (hugio.ReadSeekCloser, error) { r, err := meta.Open() @@ -74,7 +74,7 @@ func (m *pageMeta) parseFrontMatter(h *HugoSites, pid uint64) (*contentParseInfo return r, nil } } - } else if hasContent { + } else if isFromContentAdapter { openSource = m.pageConfig.Content.ValueAsOpenReadSeekCloser() } @@ -96,7 +96,9 @@ func (m *pageMeta) parseFrontMatter(h *HugoSites, pid uint64) (*contentParseInfo items, err := pageparser.ParseBytes( source, - pageparser.Config{}, + pageparser.Config{ + NoFrontMatter: isFromContentAdapter, + }, ) if err != nil { return nil, err @@ -104,7 +106,7 @@ func (m *pageMeta) parseFrontMatter(h *HugoSites, pid uint64) (*contentParseInfo pi.itemsStep1 = items - if hasContent { + if isFromContentAdapter { // No front matter. return pi, nil } diff --git a/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go b/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go index 7f0f19f1c..c7e3d96c7 100644 --- a/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go +++ b/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go @@ -585,3 +585,28 @@ value: data1 b.AssertLogNotContains("WARN") } + +func TestPagesFromGoTmplShortcodeNoPreceddingCharacterIssue12544(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +disableKinds = ['home','rss','section','sitemap','taxonomy','term'] +-- content/_content.gotmpl -- +{{ $content := dict "mediaType" "text/html" "value" "x{{< sc >}}" }} +{{ .AddPage (dict "content" $content "path" "a") }} + +{{ $content := dict "mediaType" "text/html" "value" "{{< sc >}}" }} +{{ .AddPage (dict "content" $content "path" "b") }} +-- layouts/_default/single.html -- +|{{ .Content }}| +-- layouts/shortcodes/sc.html -- +foo +{{- /**/ -}} +` + + b := hugolib.Test(t, files) + + b.AssertFileContent("public/a/index.html", "|xfoo|") + b.AssertFileContent("public/b/index.html", "|foo|") // fails +} |