From 58c8bc4609ac24f02f9b0f509cff6fc799d41440 Mon Sep 17 00:00:00 2001 From: George Cushen Date: Fri, 6 Mar 2020 21:05:17 +0000 Subject: [PATCH] feat: add options to customise length of listing summaries When `summary` is defined, the full summary text is now shown in listings. Add `summaryLength = 30` (length in words) to `config.toml` to customise automatic summaries from using `` tag or full content (when `summary` and `abstract` are not defined). Add `abstract_length = 135` (length in characters) to `params.toml` to customise truncation when `abstract` is used as the summary. Close #1374 --- exampleSite/config/_default/config.toml | 1 + exampleSite/config/_default/params.toml | 3 +++ layouts/partials/li_card.html | 4 +--- layouts/partials/li_compact.html | 6 +++--- layouts/partials/portfolio_li_card.html | 8 +++----- layouts/partials/portfolio_li_showcase.html | 4 +--- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/exampleSite/config/_default/config.toml b/exampleSite/config/_default/config.toml index 8e9b871b..0162a0d5 100644 --- a/exampleSite/config/_default/config.toml +++ b/exampleSite/config/_default/config.toml @@ -31,6 +31,7 @@ hasCJKLanguage = false # Set `true` for Chinese/Japanese/Korean languages. defaultContentLanguageInSubdir = false removePathAccents = true # Workaround for https://github.com/gohugoio/hugo/issues/5687 +summaryLength = 30 # Listing summary length in words. Also, see `abstract_length` in `params.toml`. paginate = 10 # Number of items per page in paginated lists. enableEmoji = true footnotereturnlinkcontents = "^" diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml index 71e03626..91ffc754 100644 --- a/exampleSite/config/_default/params.toml +++ b/exampleSite/config/_default/params.toml @@ -155,6 +155,9 @@ sharing = true # Link authors to their profile page? (true/false) link_authors = true +# Abstract length (characters) in the Compact and Portfolio Card list views. Also, see `summaryLength` in `config.toml`. +abstract_length = 135 + # Load JS plugins # E.g. To load `/assets/js/custom.js`, set `plugins_js = ["custom"]`. plugins_js = [] diff --git a/layouts/partials/li_card.html b/layouts/partials/li_card.html index 08dc2118..d15b7c8a 100644 --- a/layouts/partials/li_card.html +++ b/layouts/partials/li_card.html @@ -15,10 +15,8 @@ {{ $summary = $item.Params.summary | markdownify | emojify }} {{ else if .Params.abstract }} {{ $summary = .Params.abstract | markdownify | emojify }} -{{ else if $item.Truncated }} +{{ else if $item.Summary }} {{ $summary = $item.Summary }} -{{ else }} - {{ $summary = $item.Content }} {{ end }}
diff --git a/layouts/partials/li_compact.html b/layouts/partials/li_compact.html index 964634ec..95584f51 100644 --- a/layouts/partials/li_compact.html +++ b/layouts/partials/li_compact.html @@ -25,8 +25,8 @@ {{ if $item.Params.summary }} {{ $summary = $item.Params.summary | markdownify | emojify }} {{ else if .Params.abstract }} - {{ $summary = .Params.abstract | markdownify | emojify }} -{{ else if $item.Truncated }} + {{ $summary = .Params.abstract | markdownify | emojify | truncate (site.Params.abstract_length | default 135) }} +{{ else if $item.Summary }} {{ $summary = $item.Summary }} {{ end }} @@ -39,7 +39,7 @@ {{ with $summary }}
- {{ . | truncate 135 }} + {{ . }}
{{ end }} diff --git a/layouts/partials/portfolio_li_card.html b/layouts/partials/portfolio_li_card.html index 2ab8987c..2502fdd1 100644 --- a/layouts/partials/portfolio_li_card.html +++ b/layouts/partials/portfolio_li_card.html @@ -9,11 +9,9 @@ {{ if $item.Params.summary }} {{ $summary = $item.Params.summary | markdownify | emojify }} {{ else if .Params.abstract }} - {{ $summary = .Params.abstract | markdownify | emojify }} -{{ else if $item.Truncated }} + {{ $summary = .Params.abstract | markdownify | emojify | truncate (site.Params.abstract_length | default 135) }} +{{ else if $item.Summary }} {{ $summary = $item.Summary }} -{{ else }} - {{ $summary = $item.Content }} {{ end }} {{ $resource := ($item.Resources.ByType "image").GetMatch "*featured*" }} @@ -31,7 +29,7 @@

{{ $item.Title | markdownify | emojify }}

{{ with $summary }}
-

{{ . | truncate 135 }}

+

{{ . }}

{{ end }}
diff --git a/layouts/partials/portfolio_li_showcase.html b/layouts/partials/portfolio_li_showcase.html index b3a1175c..68f5f900 100644 --- a/layouts/partials/portfolio_li_showcase.html +++ b/layouts/partials/portfolio_li_showcase.html @@ -17,10 +17,8 @@ {{ $summary = $item.Params.summary | markdownify | emojify }} {{ else if .Params.abstract }} {{ $summary = .Params.abstract | markdownify | emojify }} -{{ else if $item.Truncated }} +{{ else if $item.Summary }} {{ $summary = $item.Summary }} -{{ else }} - {{ $summary = $item.Content }} {{ end }} {{ $order := "" }}