diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2016-08-01 23:04:44 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2016-09-06 18:32:16 +0300 |
commit | ed0985404db4630d1b9d3ad0b7e41fb186ae0112 (patch) | |
tree | 86d509e1a8648924d460329c67e68223b7a9b644 /helpers | |
parent | 708bc78770a0b0361908f6404f57264c53252a95 (diff) |
Render the shortcodes as late as possible
This is needed to make shortcode users happy with the new multilanguage support,
but it will also solve many other related posts about "stuff not available in the shortcode".
We will have to revisit this re the handler chain at some point, but that will be easier
now as the integration test story has improved so much.
As part of this commit, the site-building tests in page_test.go is refreshed, they now
tests for all the rendering engines (when available), and all of them now uses the
same code-path as used in production.
Fixes #1229
Fixes #2323
Fixes ##1076
Diffstat (limited to 'helpers')
-rw-r--r-- | helpers/content.go | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/helpers/content.go b/helpers/content.go index e955b0004..b9281acf4 100644 --- a/helpers/content.go +++ b/helpers/content.go @@ -41,6 +41,8 @@ var SummaryLength = 70 // SummaryDivider denotes where content summarization should end. The default is "<!--more-->". var SummaryDivider = []byte("<!--more-->") +var summaryDividerAndNewLines = []byte("<!--more-->\n\n") + // Blackfriday holds configuration values for Blackfriday rendering. type Blackfriday struct { Smartypants bool @@ -390,8 +392,21 @@ func WordCount(s string) map[string]int { } // RemoveSummaryDivider removes summary-divider <!--more--> from content. +// TODO(bep) ml remove func RemoveSummaryDivider(content []byte) []byte { - return bytes.Replace(content, SummaryDivider, []byte(""), -1) + b := bytes.Replace(content, summaryDividerAndNewLines, []byte(""), 1) + if len(b) != len(content) { + return b + } + return bytes.Replace(content, SummaryDivider, []byte(""), 1) +} + +func removeInternalSummaryDivider(content []byte) []byte { + b := bytes.Replace(content, summaryDividerAndNewLines, []byte(""), 1) + if len(b) != len(content) { + return b + } + return bytes.Replace(content, SummaryDivider, []byte(""), 1) } // TruncateWordsByRune truncates words by runes. |