mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
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.
This commit is contained in:
parent
488b21d15b
commit
26640525a3
2 changed files with 26 additions and 1 deletions
|
@ -770,7 +770,7 @@ func (c *cachedContent) contentPlain(ctx context.Context, cp *pageContentOutput)
|
||||||
result.readingTime = (result.wordCount + 212) / 213
|
result.readingTime = (result.wordCount + 212) / 213
|
||||||
}
|
}
|
||||||
|
|
||||||
if rendered.summary != "" {
|
if c.pi.hasSummaryDivider || rendered.summary != "" {
|
||||||
result.summary = rendered.summary
|
result.summary = rendered.summary
|
||||||
result.summaryTruncated = rendered.summaryTruncated
|
result.summaryTruncated = rendered.summaryTruncated
|
||||||
} else if cp.po.p.m.pageConfig.Summary != "" {
|
} else if cp.po.p.m.pageConfig.Summary != "" {
|
||||||
|
|
|
@ -63,6 +63,15 @@ Summary Next Line
|
||||||
|
|
||||||
<!--more-->
|
<!--more-->
|
||||||
Some more text
|
Some more text
|
||||||
|
`
|
||||||
|
|
||||||
|
simplePageWithBlankSummary = `---
|
||||||
|
title: SimpleWithBlankSummary
|
||||||
|
---
|
||||||
|
|
||||||
|
<!--more-->
|
||||||
|
|
||||||
|
Some text.
|
||||||
`
|
`
|
||||||
|
|
||||||
simplePageWithSummaryParameter = `---
|
simplePageWithSummaryParameter = `---
|
||||||
|
@ -351,6 +360,9 @@ func normalizeExpected(ext, str string) string {
|
||||||
|
|
||||||
return expected
|
return expected
|
||||||
case "rst":
|
case "rst":
|
||||||
|
if str == "" {
|
||||||
|
return "<div class=\"document\"></div>"
|
||||||
|
}
|
||||||
return fmt.Sprintf("<div class=\"document\">\n\n\n%s</div>", str)
|
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)
|
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) {
|
func TestPageWithSummaryParameter(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
assertFunc := func(t *testing.T, ext string, pages page.Pages) {
|
assertFunc := func(t *testing.T, ext string, pages page.Pages) {
|
||||||
|
|
Loading…
Reference in a new issue