summaryrefslogtreecommitdiffstats
path: root/hugolib/page__per_output.go
diff options
context:
space:
mode:
authorJim McDonald <Jim@mcdee.net>2019-04-05 18:11:04 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-04-05 19:11:04 +0200
commit3a62d54745e2cbfda6772390830042908d725c71 (patch)
treed039be3ac163530fa292c0bfbd50f364fad57808 /hugolib/page__per_output.go
parentebab291c0e321d23b098684bacaf830a3979e310 (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 'hugolib/page__per_output.go')
-rw-r--r--hugolib/page__per_output.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/hugolib/page__per_output.go b/hugolib/page__per_output.go
index 05b35cc87..177e0420a 100644
--- a/hugolib/page__per_output.go
+++ b/hugolib/page__per_output.go
@@ -128,6 +128,14 @@ func newPageContentOutput(p *pageState) func(f output.Format) (*pageContentOutpu
cp.summary = helpers.BytesToHTML(summary)
}
}
+ } else if cp.p.m.summary != "" {
+ html := cp.p.s.ContentSpec.RenderBytes(&helpers.RenderingContext{
+ Content: []byte(cp.p.m.summary), RenderTOC: false, PageFmt: cp.p.m.markup,
+ Cfg: p.Language(),
+ DocumentID: p.File().UniqueID(), DocumentName: p.File().Path(),
+ Config: cp.p.getRenderingConfig()})
+ html = cp.p.s.ContentSpec.TrimShortHTML(html)
+ cp.summary = helpers.BytesToHTML(html)
}
}
@@ -271,7 +279,7 @@ func (p *pageContentOutput) WordCount() int {
}
func (p *pageContentOutput) setAutoSummary() error {
- if p.p.source.hasSummaryDivider {
+ if p.p.source.hasSummaryDivider || p.p.m.summary != "" {
return nil
}