Make ContentWithoutSummary return Content when summary is fetched from front matter

Fixes #12822
This commit is contained in:
Bjørn Erik Pedersen 2024-09-04 19:07:59 +02:00
parent b570a5f118
commit 8f2eac0195
2 changed files with 18 additions and 5 deletions

View 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) {

View 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) {