From 8717a60cc030f4310c1779c0cdd51db37ad636cd Mon Sep 17 00:00:00 2001 From: Brendan Roy Date: Fri, 29 Sep 2017 17:04:55 +1000 Subject: Change SummaryLength to be configurable (#3924) Move SummaryLength into the ContentSpec struct and refactor the relevant summary functions to be methods of ContentSpec. The new summaryLength struct member is configurable by the summaryLength config value, and the default remains 70. Also updates hugolib/page to use the refactored methods. Resolves #3734 --- hugolib/config.go | 1 + hugolib/page.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'hugolib') diff --git a/hugolib/config.go b/hugolib/config.go index 2406ba771..d0ade018f 100644 --- a/hugolib/config.go +++ b/hugolib/config.go @@ -135,6 +135,7 @@ func loadDefaultSettingsFor(v *viper.Viper) error { v.SetDefault("newContentEditor", "") v.SetDefault("paginate", 10) v.SetDefault("paginatePath", "page") + v.SetDefault("summaryLength", 70) v.SetDefault("blackfriday", c.NewBlackfriday()) v.SetDefault("rSSUri", "index.xml") v.SetDefault("rssLimit", -1) diff --git a/hugolib/page.go b/hugolib/page.go index d5c444ed6..12bdf312b 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -677,9 +677,9 @@ func (p *Page) setAutoSummary() error { var summary string var truncated bool if p.isCJKLanguage { - summary, truncated = helpers.TruncateWordsByRune(p.PlainWords(), helpers.SummaryLength) + summary, truncated = p.s.ContentSpec.TruncateWordsByRune(p.PlainWords()) } else { - summary, truncated = helpers.TruncateWordsToWholeSentence(p.Plain(), helpers.SummaryLength) + summary, truncated = p.s.ContentSpec.TruncateWordsToWholeSentence(p.Plain()) } p.Summary = template.HTML(summary) p.Truncated = truncated -- cgit v1.2.3