Create description from summary

{{ partial "truncate" (dict "input" .Summary "maxLength" 50) }}
layouts/partials/truncate.html
{{ $input := .input | plainify | replaceRE `\r` "" | replaceRE `\n` " " | replaceRE `\s{2,}` " " }}
{{ $maxLength := .maxLength | int }}
{{ $endMarks := slice "." "?" "!" }}

{{ $regex := printf `(?s)^.{0,%d}\W` (sub $maxLength 1) }}
{{ $truncated := index (findRE $regex $input) 0 | replaceRE `\s+$` "" }}
{{ if not (in $endMarks (substr $truncated -1)) }}
  {{ $truncated = replaceRE `\W+$` "" $truncated }}
  {{ $truncated = print $truncated "…" }}
{{ end }}

{{ return $truncated }}

Try it:

git clone --single-branch -b hugo-forum-topic-36676 https://github.com/jmooring/hugo-testing hugo-forum-topic-36676
cd hugo-forum-topic-36676
hugo server
12 Likes