]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Fix .RawContent for empty content pages (#11407)
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 30 Aug 2023 08:11:20 +0000 (11:11 +0300)
committerGitHub <noreply@github.com>
Wed, 30 Aug 2023 08:11:20 +0000 (10:11 +0200)
Fixes #11406

hugolib/page.go
hugolib/page_test.go

index 81ba68aa42a7969a6e43d5f32871f72e13c51a5f..27a60a186a8b7b5045c67cfd269f6c06058ec719 100644 (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.
index fd115385dd92b2a5332ddf9dc170f9a6de2043fc..ecaf1dc5c93fc96cb9854c13467d59bc9a77b336 100644 (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**`)
-
-       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) {