mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-30 22:39:58 +02:00
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
``` git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash ``` Closes #11925
This commit is contained in:
36
docs/content/en/methods/page/PlainWords.md
Normal file
36
docs/content/en/methods/page/PlainWords.md
Normal file
@@ -0,0 +1,36 @@
|
||||
---
|
||||
title: PlainWords
|
||||
description: Calls the Plain method, splits the result into a slice of words, and returns the slice.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related:
|
||||
- methods/page/Content
|
||||
- methods/page/RawContent
|
||||
- methods/page/Plain
|
||||
returnType: '[]string'
|
||||
signatures: [PAGE.PlainWords]
|
||||
---
|
||||
|
||||
The `PlainWords` method on a `Page` object calls the [`Plain`] method, then uses Go's [`strings.Fields`] function to split the result into words.
|
||||
|
||||
{{% note %}}
|
||||
_Fields splits the string s around each instance of one or more consecutive white space characters, as defined by [`unicode.IsSpace`], returning a slice of substrings of s or an empty slice if s contains only white space._
|
||||
|
||||
[`unicode.IsSpace`]: https://pkg.go.dev/unicode#IsSpace
|
||||
{{% /note %}}
|
||||
|
||||
As a result, elements within the slice may contain leading or trailing punctuation.
|
||||
|
||||
```go-html-template
|
||||
{{ .PlainWords }}
|
||||
```
|
||||
|
||||
To determine the approximate number of unique words on a page:
|
||||
|
||||
```go-html-template
|
||||
{{ .PlainWords | uniq }} → 42
|
||||
```
|
||||
|
||||
[`Plain`]: /methods/page/plain
|
||||
[`strings.Fields`]: https://pkg.go.dev/strings#Fields
|
Reference in New Issue
Block a user