Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim McDonald <Jim@mcdee.net>2019-04-05 20:11:04 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-04-05 20:11:04 +0300
commit3a62d54745e2cbfda6772390830042908d725c71 (patch)
treed039be3ac163530fa292c0bfbd50f364fad57808 /hugolib/page_test.go
parentebab291c0e321d23b098684bacaf830a3979e310 (diff)
hugolib: Consider summary in front matter for .Summary
Add the ability to have a `summary` page variable that overrides the auto-generated summary. Logic for obtaining summary becomes: * if summary divider is present in content, use the text above it * if summary variables is present in page metadata, use that * auto-generate summary from first _x_ words of the content Fixes #5800
Diffstat (limited to 'hugolib/page_test.go')
-rw-r--r--hugolib/page_test.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/hugolib/page_test.go b/hugolib/page_test.go
index 6d9d337eb..a3b86ef2a 100644
--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -45,6 +45,16 @@ const (
simplePageRFC3339Date = "---\ntitle: RFC3339 Date\ndate: \"2013-05-17T16:59:30Z\"\n---\nrfc3339 content"
+ simplePageWithoutSummaryDelimiter = `---
+title: SimpleWithoutSummaryDelimiter
+---
+[Lorem ipsum](https://lipsum.com/) dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+
+Additional text.
+
+Further text.
+`
+
simplePageWithSummaryDelimiter = `---
title: Simple
---
@@ -54,6 +64,16 @@ Summary Next Line
Some more text
`
+ simplePageWithSummaryParameter = `---
+title: SimpleWithSummaryParameter
+summary: "Page with summary parameter and [a link](http://www.example.com/)"
+---
+
+Some text.
+
+Some more text.
+`
+
simplePageWithSummaryDelimiterAndMarkdownThatCrossesBorder = `---
title: Simple
---
@@ -519,6 +539,22 @@ func TestCreateNewPage(t *testing.T) {
testAllMarkdownEnginesForPages(t, assertFunc, settings, simplePage)
}
+func TestPageSummary(t *testing.T) {
+ t.Parallel()
+ assertFunc := func(t *testing.T, ext string, pages page.Pages) {
+ p := pages[0]
+ checkPageTitle(t, p, "SimpleWithoutSummaryDelimiter")
+ // Source is not Asciidoctor- or RST-compatibile so don't test them
+ if ext != "ad" && ext != "rst" {
+ checkPageContent(t, p, normalizeExpected(ext, "<p><a href=\"https://lipsum.com/\">Lorem ipsum</a> dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>\n\n<p>Additional text.</p>\n\n<p>Further text.</p>\n"), ext)
+ checkPageSummary(t, p, normalizeExpected(ext, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Additional text."), ext)
+ }
+ checkPageType(t, p, "page")
+ }
+
+ testAllMarkdownEnginesForPages(t, assertFunc, nil, simplePageWithoutSummaryDelimiter)
+}
+
func TestPageWithDelimiter(t *testing.T) {
t.Parallel()
assertFunc := func(t *testing.T, ext string, pages page.Pages) {
@@ -532,6 +568,22 @@ func TestPageWithDelimiter(t *testing.T) {
testAllMarkdownEnginesForPages(t, assertFunc, nil, simplePageWithSummaryDelimiter)
}
+func TestPageWithSummaryParameter(t *testing.T) {
+ t.Parallel()
+ assertFunc := func(t *testing.T, ext string, pages page.Pages) {
+ p := pages[0]
+ checkPageTitle(t, p, "SimpleWithSummaryParameter")
+ checkPageContent(t, p, normalizeExpected(ext, "<p>Some text.</p>\n\n<p>Some more text.</p>\n"), ext)
+ // Summary is not Asciidoctor- or RST-compatibile so don't test them
+ if ext != "ad" && ext != "rst" {
+ checkPageSummary(t, p, normalizeExpected(ext, "Page with summary parameter and <a href=\"http://www.example.com/\">a link</a>"), ext)
+ }
+ checkPageType(t, p, "page")
+ }
+
+ testAllMarkdownEnginesForPages(t, assertFunc, nil, simplePageWithSummaryParameter)
+}
+
// Issue #3854
// Also see https://github.com/gohugoio/hugo/issues/3977
func TestPageWithDateFields(t *testing.T) {