From 6c8e7edbb42f9a4b5795f195cbf18c68674e9af4 Mon Sep 17 00:00:00 2001 From: Mark Sanborn Date: Sat, 31 Aug 2013 21:07:22 -0700 Subject: [PATCH] The (summary divider) now works even if it is on the same line as content Signed-off-by: Noah Campbell --- hugolib/helpers.go | 4 ++++ hugolib/page.go | 2 +- hugolib/page_test.go | 23 ++++++++++++++++++++++- hugolib/site.go | 20 ++++++++++---------- 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/hugolib/helpers.go b/hugolib/helpers.go index cf84835fd..feed341e5 100644 --- a/hugolib/helpers.go +++ b/hugolib/helpers.go @@ -270,6 +270,10 @@ func WordCount(s string) map[string]int { return m } +func RemoveSummaryDivider(content []byte) []byte { + return bytes.Replace(content, summaryDivider, []byte(""), -1) +} + func StripHTML(s string) string { output := "" diff --git a/hugolib/page.go b/hugolib/page.go index 409da23bc..eb8f142b3 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -481,7 +481,7 @@ func (page *Page) convertMarkdown(lines io.Reader) { 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)) diff --git a/hugolib/page_test.go b/hugolib/page_test.go index a1c7c755d..4ffda4461 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -100,6 +100,14 @@ Simple Page Some more text ` +var SIMPLE_PAGE_WITH_SUMMARY_DELIMITER_SAME_LINE = `--- +title: Simple +--- +Simple Page + +Some more text +` + func checkError(t *testing.T, err error, expected string) { if err == nil { t.Fatalf("err is nil") @@ -175,7 +183,20 @@ func TestPageWithDelimiter(t *testing.T) { t.Fatalf("Unable to create a page with frontmatter and body content: %s", err) } checkPageTitle(t, p, "Simple") - checkPageContent(t, p, "

Simple Page

\n\n\n\n

Some more text

\n") + checkPageContent(t, p, "

Simple Page

\n\n

Some more text

\n") + checkPageSummary(t, p, "

Simple Page

\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, "

Simple Page

\n\n

Some more text

\n") checkPageSummary(t, p, "

Simple Page

\n") checkPageType(t, p, "page") checkPageLayout(t, p, "page/single.html") diff --git a/hugolib/site.go b/hugolib/site.go index 94e9b50dc..0b8090f79 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -31,16 +31,16 @@ import ( 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 {