]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
hugolib: Fix regression for blank summaries
authorcuregit <37978051+curegit@users.noreply.github.com>
Fri, 5 Apr 2024 15:43:55 +0000 (00:43 +0900)
committerGitHub <noreply@github.com>
Fri, 5 Apr 2024 15:43:55 +0000 (17:43 +0200)
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.

hugolib/page__content.go
hugolib/page_test.go

index 62e78c61271a80c6a6d5d6f984a78cf6ddac14e0..54f7be9618a16a25b2a84b6ed1ee40964b5c7e3f 100644 (file)
@@ -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 != "" {
index f22a4d07cd7b2271400c17216a16fffeddb1e6eb..8919c246cf5b5fe735de8c97063aecd3cc5de506 100644 (file)
@@ -63,6 +63,15 @@ Summary Next Line
 
 <!--more-->
 Some more text
+`
+
+       simplePageWithBlankSummary = `---
+title: SimpleWithBlankSummary
+---
+
+<!--more-->
+
+Some text.
 `
 
        simplePageWithSummaryParameter = `---
@@ -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) {