Fix .RawContent for empty content pages (#11407)

Fixes #11406
This commit is contained in:
Bjørn Erik Pedersen 2023-08-30 11:11:20 +03:00 committed by GitHub
parent a7b93e6564
commit 3a8aad6b19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 18 deletions

View file

@ -328,6 +328,7 @@ func (p *pageState) RawContent() string {
if start == -1 {
start = 0
}
return string(p.source.parsed.Input()[start:])
}
@ -727,9 +728,7 @@ Loop:
frontMatterSet = true
next := iter.Peek()
if !next.IsDone() {
p.source.posMainContent = next.Pos()
}
p.source.posMainContent = next.Pos()
if !p.s.shouldBuild(p) {
// Nothing more to do.

View file

@ -642,27 +642,33 @@ Simple Page With Some Date`
testAllMarkdownEnginesForPages(t, assertFunc, nil, pageContents...)
}
// Issue #2601
func TestPageRawContent(t *testing.T) {
t.Parallel()
c := qt.New(t)
cfg, fs := newTestCfg()
configs, err := loadTestConfigFromProvider(cfg)
c.Assert(err, qt.IsNil)
writeSource(t, fs, filepath.Join("content", "raw.md"), `---
title: Raw
files := `
-- hugo.toml --
-- content/basic.md --
---
**Raw**`)
title: "basic"
---
**basic**
-- content/empty.md --
---
title: "empty"
---
-- layouts/_default/single.html --
|{{ .RawContent }}|
`
writeSource(t, fs, filepath.Join("layouts", "_default", "single.html"), `{{ .RawContent }}`)
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Configs: configs}, BuildCfg{SkipRender: true})
b.AssertFileContent("public/basic/index.html", "|**basic**|")
b.AssertFileContent("public/empty/index.html", "! title")
c.Assert(len(s.RegularPages()), qt.Equals, 1)
p := s.RegularPages()[0]
c.Assert("**Raw**", qt.Equals, p.RawContent())
}
func TestPageWithShortCodeInSummary(t *testing.T) {