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
This commit is contained in:
Jim McDonald
2019-04-05 18:11:04 +01:00
committed by Bjørn Erik Pedersen
parent ebab291c0e
commit 3a62d54745
8 changed files with 115 additions and 15 deletions

View File

@@ -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.