Merge commit 'f96384a3b596f9bc0a3a035970b09b2c601f0ccb'

This commit is contained in:
Bjørn Erik Pedersen
2023-05-22 16:47:07 +02:00
341 changed files with 3107 additions and 4238 deletions

View File

@@ -1,27 +1,20 @@
---
title: truncate
# linktitle: truncate
description: Truncates a text to a max length without cutting words or leaving unclosed HTML tags.
date: 2017-02-01
publishdate: 2017-02-01
lastmod: 2017-02-01
categories: [functions]
menu:
docs:
parent: "functions"
parent: functions
keywords: [strings]
signature:
- "truncate SIZE [ELLIPSIS] INPUT"
- "strings.Truncate SIZE [ELLIPSIS] INPUT"
workson: []
hugoversion: 19
relatedfuncs: []
deprecated: false
---
Since Go templates are HTML-aware, `truncate` will intelligently handle normal strings vs HTML strings:
```
```go-html-template
{{ "<em>Keep my HTML</em>" | safeHTML | truncate 10 }}`<em>Keep my …</em>`
```