diff options
author | Jim McDonald <Jim@mcdee.net> | 2019-04-05 20:11:04 +0300 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-04-05 20:11:04 +0300 |
commit | 3a62d54745e2cbfda6772390830042908d725c71 (patch) | |
tree | d039be3ac163530fa292c0bfbd50f364fad57808 /tpl | |
parent | ebab291c0e321d23b098684bacaf830a3979e310 (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 'tpl')
-rw-r--r-- | tpl/transform/transform.go | 16 |
1 files changed, 2 insertions, 14 deletions
diff --git a/tpl/transform/transform.go b/tpl/transform/transform.go index 42e36eb0f..2aa0c1959 100644 --- a/tpl/transform/transform.go +++ b/tpl/transform/transform.go @@ -15,7 +15,6 @@ package transform import ( - "bytes" "html" "html/template" @@ -91,12 +90,6 @@ func (ns *Namespace) HTMLUnescape(s interface{}) (string, error) { return html.UnescapeString(ss), nil } -var ( - markdownTrimPrefix = []byte("<p>") - markdownTrimSuffix = []byte("</p>\n") - markdownParagraphIndicator = []byte("<p") -) - // Markdownify renders a given input from Markdown to HTML. func (ns *Namespace) Markdownify(s interface{}) (template.HTML, error) { ss, err := cast.ToStringE(s) @@ -114,14 +107,9 @@ func (ns *Namespace) Markdownify(s interface{}) (template.HTML, error) { ) // Strip if this is a short inline type of text. - first := bytes.Index(m, markdownParagraphIndicator) - last := bytes.LastIndex(m, markdownParagraphIndicator) - if first == last { - m = bytes.TrimPrefix(m, markdownTrimPrefix) - m = bytes.TrimSuffix(m, markdownTrimSuffix) - } + m = ns.deps.ContentSpec.TrimShortHTML(m) - return template.HTML(m), nil + return helpers.BytesToHTML(m), nil } // Plainify returns a copy of s with all HTML tags removed. |