aboutsummaryrefslogtreecommitdiffhomepage
path: root/hugolib
diff options
context:
space:
mode:
authorcuregit <[email protected]>2024-04-06 00:43:55 +0900
committerGitHub <[email protected]>2024-04-05 17:43:55 +0200
commit26640525a313ef284c26866e5138b7189e841a22 (patch)
tree59b583f7018bd34af67e757ca66b7be0f7936048 /hugolib
parent488b21d15b51f19f790922311ec13b16d784e1f7 (diff)
downloadhugo-26640525a313ef284c26866e5138b7189e841a22.tar.gz
hugo-26640525a313ef284c26866e5138b7189e841a22.zip
hugolib: Fix regression for blank summaries
Fix regression in content summarization so that we can use empty summary by using the manual summary divider. Since v0.123, there has been the regression that causes Hugo to use automatic summary generation when the manual summary results in an empty string, even if there is a `<!--more-->` summary divider.
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/page__content.go2
-rw-r--r--hugolib/page_test.go25
2 files changed, 26 insertions, 1 deletions
diff --git a/hugolib/page__content.go b/hugolib/page__content.go
index 62e78c612..54f7be961 100644
--- a/hugolib/page__content.go
+++ b/hugolib/page__content.go
@@ -770,7 +770,7 @@ func (c *cachedContent) contentPlain(ctx context.Context, cp *pageContentOutput)
result.readingTime = (result.wordCount + 212) / 213
}
- if rendered.summary != "" {
+ if c.pi.hasSummaryDivider || rendered.summary != "" {
result.summary = rendered.summary
result.summaryTruncated = rendered.summaryTruncated
} else if cp.po.p.m.pageConfig.Summary != "" {
diff --git a/hugolib/page_test.go b/hugolib/page_test.go
index f22a4d07c..8919c246c 100644
--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -65,6 +65,15 @@ Summary Next Line
Some more text
`
+ simplePageWithBlankSummary = `---
+title: SimpleWithBlankSummary
+---
+
+<!--more-->
+
+Some text.
+`
+
simplePageWithSummaryParameter = `---
title: SimpleWithSummaryParameter
summary: "Page with summary parameter and [a link](http://www.example.com/)"
@@ -351,6 +360,9 @@ func normalizeExpected(ext, str string) string {
return expected
case "rst":
+ if str == "" {
+ return "<div class=\"document\"></div>"
+ }
return fmt.Sprintf("<div class=\"document\">\n\n\n%s</div>", str)
}
}
@@ -630,6 +642,19 @@ func TestPageWithDelimiter(t *testing.T) {
testAllMarkdownEnginesForPages(t, assertFunc, nil, simplePageWithSummaryDelimiter)
}
+func TestPageWithBlankSummary(t *testing.T) {
+ t.Parallel()
+ assertFunc := func(t *testing.T, ext string, pages page.Pages) {
+ p := pages[0]
+ checkPageTitle(t, p, "SimpleWithBlankSummary")
+ checkPageContent(t, p, normalizeExpected(ext, "<p>Some text.</p>\n"), ext)
+ checkPageSummary(t, p, normalizeExpected(ext, ""), ext)
+ checkPageType(t, p, "page")
+ }
+
+ testAllMarkdownEnginesForPages(t, assertFunc, nil, simplePageWithBlankSummary)
+}
+
func TestPageWithSummaryParameter(t *testing.T) {
t.Parallel()
assertFunc := func(t *testing.T, ext string, pages page.Pages) {