shithub: hugo

Download patch

ref: 6c8e7edbb42f9a4b5795f195cbf18c68674e9af4
parent: 4349216debc66642c5ef33ffdcbdfcf0a58a9a9b
author: Mark Sanborn <[email protected]>
date: Sat Aug 31 17:07:22 EDT 2013

The <!--more--> (summary divider) now works even if it is on the same line as content

Signed-off-by: Noah Campbell <[email protected]>

--- a/hugolib/helpers.go
+++ b/hugolib/helpers.go
@@ -270,6 +270,10 @@
 	return m
 }
 
+func RemoveSummaryDivider(content []byte) []byte {
+	return bytes.Replace(content, summaryDivider, []byte(""), -1)
+}
+
 func StripHTML(s string) string {
 	output := ""
 
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -481,7 +481,7 @@
 	b := new(bytes.Buffer)
 	b.ReadFrom(lines)
 	content := b.Bytes()
-	page.Content = template.HTML(string(blackfriday.MarkdownCommon(content)))
+	page.Content = template.HTML(string(blackfriday.MarkdownCommon(RemoveSummaryDivider(content))))
 	summary, plain := getSummaryString(content)
 	if plain {
 		page.Summary = template.HTML(string(summary))
--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -100,6 +100,14 @@
 Some more text
 `
 
+var SIMPLE_PAGE_WITH_SUMMARY_DELIMITER_SAME_LINE = `---
+title: Simple
+---
+Simple Page<!--more-->
+
+Some more text
+`
+
 func checkError(t *testing.T, err error, expected string) {
 	if err == nil {
 		t.Fatalf("err is nil")
@@ -175,7 +183,20 @@
 		t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
 	}
 	checkPageTitle(t, p, "Simple")
-	checkPageContent(t, p, "<p>Simple Page</p>\n\n<!--more-->\n\n<p>Some more text</p>\n")
+	checkPageContent(t, p, "<p>Simple Page</p>\n\n<p>Some more text</p>\n")
+	checkPageSummary(t, p, "<p>Simple Page</p>\n")
+	checkPageType(t, p, "page")
+	checkPageLayout(t, p, "page/single.html")
+
+}
+
+func TestPageWithMoreTag(t *testing.T) {
+	p, err := ReadFrom(strings.NewReader(SIMPLE_PAGE_WITH_SUMMARY_DELIMITER_SAME_LINE), "simple")
+	if err != nil {
+		t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
+	}
+	checkPageTitle(t, p, "Simple")
+	checkPageContent(t, p, "<p>Simple Page</p>\n\n<p>Some more text</p>\n")
 	checkPageSummary(t, p, "<p>Simple Page</p>\n")
 	checkPageType(t, p, "page")
 	checkPageLayout(t, p, "page/single.html")
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -31,16 +31,16 @@
 var DefaultTimer = nitro.Initalize()
 
 type Site struct {
-	Config      Config
-	Pages       Pages
-	Tmpl        *template.Template
-	Indexes     IndexList
-	Files       []string
-	Sections    Index
-	Info        SiteInfo
-	Shortcodes  map[string]ShortcodeFunc
-	timer       *nitro.B
-	Target      target.Publisher
+	Config     Config
+	Pages      Pages
+	Tmpl       *template.Template
+	Indexes    IndexList
+	Files      []string
+	Sections   Index
+	Info       SiteInfo
+	Shortcodes map[string]ShortcodeFunc
+	timer      *nitro.B
+	Target     target.Publisher
 }
 
 type SiteInfo struct {