]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Make ContentWithoutSummary return Content when summary is fetched from front matter
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 4 Sep 2024 17:07:59 +0000 (19:07 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 5 Sep 2024 10:12:24 +0000 (12:12 +0200)
Fixes #12822

hugolib/page__content.go
resources/page/page_markup_integration_test.go

index cc93fe5d5cf15308188c31f58cbcab35e9762be7..4ec91f7b5cd1922a5837da09425c0c00c3f08292 100644 (file)
@@ -504,7 +504,7 @@ type contentTableOfContents struct {
 }
 
 type contentSummary struct {
-       content               string
+       content               template.HTML
        contentWithoutSummary template.HTML
        summary               page.Summary
 }
@@ -612,9 +612,9 @@ func (c *cachedContentScope) contentRendered(ctx context.Context) (contentSummar
                                        Truncated: summarized.Truncated(),
                                }
                                result.contentWithoutSummary = template.HTML(summarized.ContentWithoutSummary())
-                               result.content = summarized.Content()
+                               result.content = template.HTML(summarized.Content())
                        } else {
-                               result.content = string(b)
+                               result.content = template.HTML(string(b))
                        }
 
                        if !c.pi.hasSummaryDivider && cp.po.p.m.pageConfig.Summary == "" {
@@ -646,6 +646,7 @@ func (c *cachedContentScope) contentRendered(ctx context.Context) (contentSummar
                                Text: helpers.BytesToHTML(html),
                                Type: page.SummaryTypeFrontMatter,
                        }
+                       rs.Value.contentWithoutSummary = rs.Value.content
                }
 
                return rs, err
@@ -879,7 +880,7 @@ func (c *cachedContentScope) Content(ctx context.Context) (template.HTML, error)
        if err != nil {
                return "", err
        }
-       return template.HTML(cr.content), nil
+       return cr.content, nil
 }
 
 func (c *cachedContentScope) ContentWithoutSummary(ctx context.Context) (template.HTML, error) {
index fc3c6a5691e644a84a1e0b07478740687aa33ae8..010a9d729a5775a0b01426fcc7a0aa3f68369c19 100644 (file)
@@ -171,7 +171,7 @@ includecontent: {{ hugo.Context.MarkupScope }}|{{ $p.Markup.Render.Content }}|
        )
 }
 
-func TestPageMarkupWithoutSummary(t *testing.T) {
+func TestPageContentWithoutSummary(t *testing.T) {
        t.Parallel()
 
        files := `
@@ -195,6 +195,13 @@ This is some content about a summary and more.
 Another paragraph.
 
 Third paragraph.
+-- content/p3.md --
+---
+title: "Post 3"
+date: "2020-01-01"
+summary: "This is summary in front matter."
+---
+This is content.
 -- layouts/_default/single.html --
 Single.
 Page.Summary: {{ .Summary }}|
@@ -229,6 +236,11 @@ Summary Truncated: {{ .Truncated }}|
                "Summary Type: auto",
                "Summary Truncated: true",
        )
+
+       b.AssertFileContentExact("public/p3/index.html",
+               "Summary: This is summary in front matter.|",
+               "ContentWithoutSummary: <p>This is content.</p>\n|",
+       )
 }
 
 func TestPageMarkupWithoutSummaryRST(t *testing.T) {