Ver código fonte

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 `<!--more-->` 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
George Cushen 5 anos atrás
pai
commit
58c8bc4609

+ 1 - 0
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 = "<sup>^</sup>"

+ 3 - 0
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  = []

+ 1 - 3
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 }}
 
 <div class="card-simple">

+ 3 - 3
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 }}
     <div class="article-style">
-      {{ . | truncate 135 }}
+      {{ . }}
     </div>
     {{ end }}
 

+ 3 - 5
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 @@
       <h4><a href="{{ $link }}" {{ $target | safeHTMLAttr }}>{{ $item.Title | markdownify | emojify }}</a></h4>
       {{ with $summary }}
       <div class="article-style">
-        <p>{{ . | truncate 135 }}</p>
+        <p>{{ . }}</p>
       </div>
       {{ end }}
     </div>

+ 1 - 3
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 := "" }}