diff --git a/hugolib/page__content.go b/hugolib/page__content.go index 4b78a1ed0..d2a68c24b 100644 --- a/hugolib/page__content.go +++ b/hugolib/page__content.go @@ -645,8 +645,9 @@ func (c *cachedContentScope) contentRendered(ctx context.Context) (contentSummar } html := cp.po.p.s.ContentSpec.TrimShortHTML(b.Bytes(), cp.po.p.m.pageConfig.Content.Markup) rs.Value.summary = page.Summary{ - Text: helpers.BytesToHTML(html), - Type: page.SummaryTypeFrontMatter, + Text: helpers.BytesToHTML(html), + Type: page.SummaryTypeFrontMatter, + Truncated: rs.Value.summary.Truncated, } rs.Value.contentWithoutSummary = rs.Value.content } diff --git a/resources/page/page_markup.go b/resources/page/page_markup.go index 44980e8b0..8f58fc2ab 100644 --- a/resources/page/page_markup.go +++ b/resources/page/page_markup.go @@ -104,7 +104,7 @@ func (s HtmlSummary) trimSpace(ss string) string { func (s HtmlSummary) Content() string { if s.Divider.IsZero() { - return s.source + return s.trimSpace(s.source) } ss := s.source[:s.Divider.Low] ss += s.source[s.Divider.High:] @@ -139,7 +139,7 @@ func (s HtmlSummary) ContentWithoutSummary() string { } func (s HtmlSummary) Truncated() bool { - return s.SummaryLowHigh.High < len(s.source) + return s.Summary() != s.Content() } func (s *HtmlSummary) resolveParagraphTagAndSetWrapper(mt media.Type) tagReStartEnd { diff --git a/resources/page/page_markup_integration_test.go b/resources/page/page_markup_integration_test.go index 425099215..b8e010e21 100644 --- a/resources/page/page_markup_integration_test.go +++ b/resources/page/page_markup_integration_test.go @@ -14,6 +14,8 @@ package page_test import ( + "strconv" + "strings" "testing" "github.com/gohugoio/hugo/hugolib" @@ -347,3 +349,74 @@ Summary Truncated: {{ .Truncated }}| "Summary:
\n

This is summary.

\n
|\nSummary Type: manual|\nSummary Truncated: true|", ) } + +func TestIssue13967(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +disableKinds = ['home','rss','section','sitemap','taxonomy','term'] +-- layouts/all.html -- +Title: {{ .Title }}|Summary: {{ .Summary }}|Truncated: {{ .Truncated }}| +-- content/p1.md -- +--- +title: p1 +--- + one two three +-- content/p2.md -- +--- +title: p2 +--- +one two three +-- content/p3.md -- +--- +title: p3 +--- +one two three +-- content/p4.md -- +--- +title: p4 +--- +one two three +` + b := hugolib.Test(t, files) + + b.AssertFileContent("public/p1/index.html", `Title: p1|Summary: |Truncated: true|`) + b.AssertFileContent("public/p2/index.html", `Title: p2|Summary:

one

|Truncated: true|`) + b.AssertFileContent("public/p3/index.html", `Title: p3|Summary:

one two

|Truncated: true|`) + b.AssertFileContent("public/p4/index.html", `Title: p4|Summary:

one two three

|Truncated: false|`) +} + +func TestIssue13968(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +disableKinds = ['page','rss','section','sitemap','taxonomy','term'] +summaryLength = SUMMARY_LENGTH +-- layouts/all.html -- +Title: {{ .Title }}|Summary: {{ .Summary }}|Truncated: {{ .Truncated }}| +-- content/_index.md -- +--- +title: home +--- +one two three +` + + tests := []struct { + summaryLength int + want string + }{ + {0, "Title: home|Summary: |Truncated: true|"}, + {1, "Title: home|Summary:

one two three

|Truncated: false|"}, + {2, "Title: home|Summary:

one two three

|Truncated: false|"}, + {3, "Title: home|Summary:

one two three

|Truncated: false|"}, + {4, "Title: home|Summary:

one two three

|Truncated: false|"}, + } + + for _, tt := range tests { + f := strings.ReplaceAll(files, "SUMMARY_LENGTH", strconv.Itoa(tt.summaryLength)) + b := hugolib.Test(t, f) + b.AssertFileContent("public/index.html", tt.want) + } +}