shithub: hugo

Download patch

ref: 94ab125b27a29a65e5ea45efd99dd247084b4c37
parent: dcfeed35c6e14c1ce593d23be9d2b89c66ce9bee
author: Bjørn Erik Pedersen <[email protected]>
date: Sat Nov 24 12:06:26 EST 2018

parser/pageparser: Fix when only shortcode and then summary

Fixes #5464

--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -1510,6 +1510,15 @@
 Content.
 `)
 
+	// https://github.com/gohugoio/hugo/issues/5464
+	b.WithContent("page-md-only-shortcode.md", `---
+title: "Hugo"
+---
+{{< sc >}}
+<!--more--> 
+{{< sc >}}
+`)
+
 	b.WithContent("page-md-shortcode-same-line.md", `---
 title: "Hugo"
 ---
@@ -1569,6 +1578,11 @@
 	b.AssertFileContent("public/page-org-variant1/index.html",
 		"SUMMARY:<p>Summary.</p>:END",
 		"CONTENT:<p>Summary.</p>\n\n<p>Content.\t</p>\n",
+	)
+
+	b.AssertFileContent("public/page-md-only-shortcode/index.html",
+		"SUMMARY:a shortcode:END",
+		"CONTENT:a shortcode\n\na shortcode\n",
 	)
 }
 
--- a/parser/pageparser/pagelexer.go
+++ b/parser/pageparser/pagelexer.go
@@ -216,7 +216,7 @@
 	}
 
 	l2 = l.index(leftDelimSc)
-	skip := minPositiveIndex(l1, l2)
+	skip := minIndex(l1, l2)
 
 	if skip > 0 {
 		l.pos += skip
@@ -730,12 +730,12 @@
 
 // helper functions
 
-// returns the min index > 0
-func minPositiveIndex(indices ...int) int {
+// returns the min index >= 0
+func minIndex(indices ...int) int {
 	min := -1
 
 	for _, j := range indices {
-		if j <= 0 {
+		if j < 0 {
 			continue
 		}
 		if min == -1 {
--- a/parser/pageparser/pagelexer_test.go
+++ b/parser/pageparser/pagelexer_test.go
@@ -19,11 +19,11 @@
 	"github.com/stretchr/testify/require"
 )
 
-func TestMinPositiveIndex(t *testing.T) {
+func TestMinIndex(t *testing.T) {
 	assert := require.New(t)
-	assert.Equal(1, minPositiveIndex(4, 1, 2, 3))
-	assert.Equal(2, minPositiveIndex(4, 0, -2, 2, 5))
-	assert.Equal(-1, minPositiveIndex())
-	assert.Equal(-1, minPositiveIndex(-2, -3))
+	assert.Equal(1, minIndex(4, 1, 2, 3))
+	assert.Equal(0, minIndex(4, 0, -2, 2, 5))
+	assert.Equal(-1, minIndex())
+	assert.Equal(-1, minIndex(-2, -3))
 
 }
--- a/parser/pageparser/pageparser_intro_test.go
+++ b/parser/pageparser/pageparser_intro_test.go
@@ -39,6 +39,7 @@
 	tstSomeText            = nti(tText, "\nSome text.\n")
 	tstSummaryDivider      = nti(TypeLeadSummaryDivider, "<!--more-->\n")
 	tstHtmlStart           = nti(TypeHTMLStart, "<")
+	tstNewline             = nti(tText, "\n")
 
 	tstORG = `
 #+TITLE: T1
@@ -70,6 +71,8 @@
 	{"Summary divider same line", "+++\nfoo = \"bar\"\n+++\n\nSome text.<!--more-->Some text.\n", []Item{tstFrontMatterTOML, nti(tText, "\nSome text."), nti(TypeLeadSummaryDivider, "<!--more-->"), nti(tText, "Some text.\n"), tstEOF}},
 	// https://github.com/gohugoio/hugo/issues/5402
 	{"Summary and shortcode, no space", "+++\nfoo = \"bar\"\n+++\n\nSome text.\n<!--more-->{{< sc1 >}}\nSome text.\n", []Item{tstFrontMatterTOML, tstSomeText, nti(TypeLeadSummaryDivider, "<!--more-->"), tstLeftNoMD, tstSC1, tstRightNoMD, tstSomeText, tstEOF}},
+	// https://github.com/gohugoio/hugo/issues/5464
+	{"Summary and shortcode only", "+++\nfoo = \"bar\"\n+++\n{{< sc1 >}}\n<!--more-->\n{{< sc2 >}}", []Item{tstFrontMatterTOML, tstLeftNoMD, tstSC1, tstRightNoMD, tstNewline, tstSummaryDivider, tstLeftNoMD, tstSC2, tstRightNoMD, tstEOF}},
 }
 
 func TestFrontMatter(t *testing.T) {