mirror of
https://github.com/gohugoio/hugo.git
synced 2025-09-11 13:41:14 -04:00
parent
3b8947d821
commit
d8774d7fc3
@ -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)
|
html := cp.po.p.s.ContentSpec.TrimShortHTML(b.Bytes(), cp.po.p.m.pageConfig.Content.Markup)
|
||||||
rs.Value.summary = page.Summary{
|
rs.Value.summary = page.Summary{
|
||||||
Text: helpers.BytesToHTML(html),
|
Text: helpers.BytesToHTML(html),
|
||||||
Type: page.SummaryTypeFrontMatter,
|
Type: page.SummaryTypeFrontMatter,
|
||||||
|
Truncated: rs.Value.summary.Truncated,
|
||||||
}
|
}
|
||||||
rs.Value.contentWithoutSummary = rs.Value.content
|
rs.Value.contentWithoutSummary = rs.Value.content
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ func (s HtmlSummary) trimSpace(ss string) string {
|
|||||||
|
|
||||||
func (s HtmlSummary) Content() string {
|
func (s HtmlSummary) Content() string {
|
||||||
if s.Divider.IsZero() {
|
if s.Divider.IsZero() {
|
||||||
return s.source
|
return s.trimSpace(s.source)
|
||||||
}
|
}
|
||||||
ss := s.source[:s.Divider.Low]
|
ss := s.source[:s.Divider.Low]
|
||||||
ss += s.source[s.Divider.High:]
|
ss += s.source[s.Divider.High:]
|
||||||
@ -139,7 +139,7 @@ func (s HtmlSummary) ContentWithoutSummary() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s HtmlSummary) Truncated() bool {
|
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 {
|
func (s *HtmlSummary) resolveParagraphTagAndSetWrapper(mt media.Type) tagReStartEnd {
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
package page_test
|
package page_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/hugolib"
|
"github.com/gohugoio/hugo/hugolib"
|
||||||
@ -347,3 +349,74 @@ Summary Truncated: {{ .Truncated }}|
|
|||||||
"Summary: <div class=\"paragraph\">\n<p>This is summary.</p>\n</div>|\nSummary Type: manual|\nSummary Truncated: true|",
|
"Summary: <div class=\"paragraph\">\n<p>This is summary.</p>\n</div>|\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
|
||||||
|
---
|
||||||
|
<!--more--> one two three
|
||||||
|
-- content/p2.md --
|
||||||
|
---
|
||||||
|
title: p2
|
||||||
|
---
|
||||||
|
one <!--more--> two three
|
||||||
|
-- content/p3.md --
|
||||||
|
---
|
||||||
|
title: p3
|
||||||
|
---
|
||||||
|
one two <!--more--> three
|
||||||
|
-- content/p4.md --
|
||||||
|
---
|
||||||
|
title: p4
|
||||||
|
---
|
||||||
|
one two three <!--more-->
|
||||||
|
`
|
||||||
|
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: <p>one</p>|Truncated: true|`)
|
||||||
|
b.AssertFileContent("public/p3/index.html", `Title: p3|Summary: <p>one two</p>|Truncated: true|`)
|
||||||
|
b.AssertFileContent("public/p4/index.html", `Title: p4|Summary: <p>one two three</p>|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: <p>one two three</p>|Truncated: false|"},
|
||||||
|
{2, "Title: home|Summary: <p>one two three</p>|Truncated: false|"},
|
||||||
|
{3, "Title: home|Summary: <p>one two three</p>|Truncated: false|"},
|
||||||
|
{4, "Title: home|Summary: <p>one two three</p>|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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user