From 3a8aad6b190bb3d7cecc8ec6bc8379a01ec547cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 30 Aug 2023 11:11:20 +0300 Subject: Fix .RawContent for empty content pages (#11407) Fixes #11406 --- hugolib/page.go | 5 ++--- hugolib/page_test.go | 36 +++++++++++++++++++++--------------- 2 files changed, 23 insertions(+), 18 deletions(-) (limited to 'hugolib') diff --git a/hugolib/page.go b/hugolib/page.go index 81ba68aa4..27a60a186 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -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. diff --git a/hugolib/page_test.go b/hugolib/page_test.go index fd115385d..ecaf1dc5c 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -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**`) - - writeSource(t, fs, filepath.Join("layouts", "_default", "single.html"), `{{ .RawContent }}`) +title: "basic" +--- +**basic** +-- content/empty.md -- +--- +title: "empty" +--- +-- layouts/_default/single.html -- +|{{ .RawContent }}| +` - s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Configs: configs}, BuildCfg{SkipRender: true}) + b := NewIntegrationTestBuilder( + IntegrationTestConfig{ + T: t, + TxtarString: files, + }, + ).Build() - c.Assert(len(s.RegularPages()), qt.Equals, 1) - p := s.RegularPages()[0] + b.AssertFileContent("public/basic/index.html", "|**basic**|") + b.AssertFileContent("public/empty/index.html", "! title") - c.Assert("**Raw**", qt.Equals, p.RawContent()) } func TestPageWithShortCodeInSummary(t *testing.T) { -- cgit v1.2.3