Skip to content

Commit

Permalink
Make ContentWithoutSummary return Content when summary is fetched fro…
Browse files Browse the repository at this point in the history
…m front matter

Fixes #12822
  • Loading branch information
bep committed Sep 5, 2024
1 parent b570a5f commit 8f2eac0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
9 changes: 5 additions & 4 deletions hugolib/page__content.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ type contentTableOfContents struct {
}

type contentSummary struct {
content string
content template.HTML
contentWithoutSummary template.HTML
summary page.Summary
}
Expand Down Expand Up @@ -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 == "" {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 13 additions & 1 deletion resources/page/page_markup_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := `
Expand All @@ -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 }}|
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 8f2eac0

Please sign in to comment.