# Create description from summary

**URL:** <https://discourse.gohugo.io/t/create-description-from-summary/36676>\
**Category:** support\
**Created:** [January 20, 2022, 1:52pm UTC](https://discourse.gohugo.io/t/create-description-from-summary/36676 "2022-01-20T13:52:42Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [January 22, 2022, 2:09am UTC](https://discourse.gohugo.io/t/create-description-from-summary/36676/5 "2022-01-22T02:09:16Z")

</div>

```auto
{{ partial "truncate" (dict "input" .Summary "maxLength" 50) }}

```

> **layouts/partials/truncate.html**
>
> ```auto
> {{ $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:

```bash
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

```

---

_[View the full topic](https://discourse.gohugo.io/t/create-description-from-summary/36676)._
