mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-22 21:42:50 +02:00
Merge commit '7125ad401ad043e46262afc7eca8dceb6d54bb9e'
This commit is contained in:
@@ -7,7 +7,6 @@ action:
|
||||
aliases: [append]
|
||||
related:
|
||||
- functions/collections/Merge
|
||||
- functions/collections/Slice
|
||||
returnType: any
|
||||
signatures:
|
||||
- collections.Append ELEMENT [ELEMENT...] COLLECTION
|
||||
@@ -82,7 +81,7 @@ To create a slice of slices, starting with an empty slice:
|
||||
{{ $s = $s | append (slice (slice "a" "b")) }}
|
||||
{{ $s }} → [[a b]]
|
||||
|
||||
{{ $s = $s | append (slice "c" "d") }}
|
||||
{{ $s = $s | append (slice "c" "d") }}
|
||||
{{ $s }} → [[a b] [c d]]
|
||||
```
|
||||
|
||||
|
@@ -5,14 +5,9 @@ categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [apply]
|
||||
related: []
|
||||
returnType: '[]any'
|
||||
signatures: [collections.Apply COLLECTION FUNCTION PARAM...]
|
||||
relatedFunctions:
|
||||
- collections.Delimit
|
||||
- collections.In
|
||||
- collections.Reverse
|
||||
- collections.Seq
|
||||
- collections.Slice
|
||||
aliases: [/functions/apply]
|
||||
---
|
||||
|
||||
|
@@ -6,11 +6,6 @@ keywords: []
|
||||
action:
|
||||
aliases: [delimit]
|
||||
related:
|
||||
- functions/collections/Apply
|
||||
- functions/collections/In
|
||||
- functions/collections/Reverse
|
||||
- functions/collections/Seq
|
||||
- functions/collections/Slice
|
||||
- functions/strings/Split
|
||||
returnType: string
|
||||
signatures: ['collections.Delimit COLLECTION DELIMITER [LAST]']
|
||||
|
@@ -6,10 +6,7 @@ keywords: []
|
||||
action:
|
||||
aliases: [dict]
|
||||
related:
|
||||
- functions/collections/Group
|
||||
- functions/collections/IndexFunction
|
||||
- functions/collections/IsSet
|
||||
- functions/collections/Where
|
||||
- functions/collections/Slice
|
||||
returnType: mapany
|
||||
signatures: ['collections.Dictionary KEY VALUE [VALUE...]']
|
||||
aliases: [/functions/dict]
|
||||
|
@@ -8,6 +8,7 @@ action:
|
||||
related:
|
||||
- functions/collections/After
|
||||
- functions/collections/Last
|
||||
- methods/pages/Limit
|
||||
returnType: any
|
||||
signatures: [collections.First N COLLECTION]
|
||||
aliases: [/functions/first]
|
||||
|
@@ -5,11 +5,7 @@ categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [group]
|
||||
related:
|
||||
- functions/collections/Dictionary
|
||||
- functions/collections/IndexFunction
|
||||
- functions/collections/IsSet
|
||||
- functions/collections/Where
|
||||
related: []
|
||||
returnType: any
|
||||
signatures: [collections.Group KEY PAGES]
|
||||
aliases: [/functions/group]
|
||||
|
@@ -6,7 +6,6 @@ keywords: []
|
||||
action:
|
||||
aliases: [in]
|
||||
related:
|
||||
- functions/collections/Slice
|
||||
- functions/strings/Contains
|
||||
- functions/strings/ContainsAny
|
||||
- functions/strings/ContainsNonSpace
|
||||
|
@@ -5,11 +5,7 @@ categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [index]
|
||||
related:
|
||||
- functions/collections/Dictionary
|
||||
- functions/collections/Group
|
||||
- functions/collections/IsSet
|
||||
- functions/collections/Where
|
||||
related: []
|
||||
returnType: any
|
||||
signatures:
|
||||
- collections.Index COLLECTION INDEXES
|
||||
|
@@ -6,10 +6,6 @@ keywords: []
|
||||
action:
|
||||
aliases: [isset]
|
||||
related:
|
||||
- functions/collections/Dictionary
|
||||
- functions/collections/Group
|
||||
- functions/collections/IndexFunction
|
||||
- functions/collections/Where
|
||||
- functions/go-template/if
|
||||
- functions/go-template/with
|
||||
returnType: bool
|
||||
|
@@ -8,6 +8,7 @@ action:
|
||||
related:
|
||||
- methods/page/scratch
|
||||
- methods/page/store
|
||||
- methods/shortcode/scratch
|
||||
returnType: maps.Scratch
|
||||
signatures: [collections.NewScratch ]
|
||||
---
|
||||
@@ -20,16 +21,18 @@ The `collections.NewScratch` function creates a locally scoped [scratch pad] to
|
||||
|
||||
## Methods
|
||||
|
||||
Set
|
||||
: Sets the value of a given key.
|
||||
###### Set
|
||||
|
||||
Sets the value of a given key.
|
||||
|
||||
```go-html-template
|
||||
{{ $s := newScratch }}
|
||||
{{ $s.Set "greeting" "Hello" }}
|
||||
```
|
||||
|
||||
Get
|
||||
: Gets the value of a given key.
|
||||
###### Get
|
||||
|
||||
Gets the value of a given key.
|
||||
|
||||
```go-html-template
|
||||
{{ $s := newScratch }}
|
||||
@@ -37,10 +40,11 @@ Get
|
||||
{{ $s.Get "greeting" }} → Hello
|
||||
```
|
||||
|
||||
Add
|
||||
: Adds a given value to existing value(s) of the given key.
|
||||
###### Add
|
||||
|
||||
: For single values, `Add` accepts values that support Go's `+` operator. If the first `Add` for a key is an array or slice, the following adds will be appended to that list.
|
||||
Adds a given value to existing value(s) of the given key.
|
||||
|
||||
For single values, `Add` accepts values that support Go's `+` operator. If the first `Add` for a key is an array or slice, the following adds will be appended to that list.
|
||||
|
||||
```go-html-template
|
||||
{{ $s := newScratch }}
|
||||
@@ -63,8 +67,9 @@ Add
|
||||
{{ $s.Get "greetings" }} → [Hello Welcome Cheers]
|
||||
```
|
||||
|
||||
SetInMap
|
||||
: Takes a `key`, `mapKey` and `value` and adds a map of `mapKey` and `value` to the given `key`.
|
||||
###### SetInMap
|
||||
|
||||
Takes a `key`, `mapKey` and `value` and adds a map of `mapKey` and `value` to the given `key`.
|
||||
|
||||
```go-html-template
|
||||
{{ $s := newScratch }}
|
||||
@@ -73,8 +78,9 @@ SetInMap
|
||||
{{ $s.Get "greetings" }} → map[english:Hello french:Bonjour]
|
||||
```
|
||||
|
||||
DeleteInMap
|
||||
: Takes a `key` and `mapKey` and removes the map of `mapKey` from the given `key`.
|
||||
###### DeleteInMap
|
||||
|
||||
Takes a `key` and `mapKey` and removes the map of `mapKey` from the given `key`.
|
||||
|
||||
```go-html-template
|
||||
{{ $s := newScratch }}
|
||||
@@ -84,8 +90,9 @@ DeleteInMap
|
||||
{{ $s.Get "greetings" }} → map[french:Bonjour]
|
||||
```
|
||||
|
||||
GetSortedMapValues
|
||||
: Returns an array of values from `key` sorted by `mapKey`.
|
||||
###### GetSortedMapValues
|
||||
|
||||
Returns an array of values from `key` sorted by `mapKey`.
|
||||
|
||||
```go-html-template
|
||||
{{ $s := newScratch }}
|
||||
@@ -94,8 +101,9 @@ GetSortedMapValues
|
||||
{{ $s.GetSortedMapValues "greetings" }} → [Hello Bonjour]
|
||||
```
|
||||
|
||||
Delete
|
||||
: Removes the given key.
|
||||
###### Delete
|
||||
|
||||
Removes the given key.
|
||||
|
||||
```go-html-template
|
||||
{{ $s := newScratch }}
|
||||
@@ -103,8 +111,9 @@ Delete
|
||||
{{ $s.Delete "greeting" }}
|
||||
```
|
||||
|
||||
Values
|
||||
: Returns the raw backing map. Do not use with `Scratch` or `Store` methods on a `Page` object due to concurrency issues.
|
||||
###### Values
|
||||
|
||||
Returns the raw backing map. Do not use with `Scratch` or `Store` methods on a `Page` object due to concurrency issues.
|
||||
|
||||
```go-html-template
|
||||
{{ $s := newScratch }}
|
||||
|
@@ -5,13 +5,12 @@ categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [querify]
|
||||
related:
|
||||
- functions/go-template/urlquery.md
|
||||
returnType: string
|
||||
signatures:
|
||||
- collections.Querify VALUE [VALUE...]
|
||||
- collections.Querify COLLECTION
|
||||
related:
|
||||
- collections.Querify
|
||||
- urlquery
|
||||
aliases: [/functions/querify]
|
||||
---
|
||||
|
||||
|
@@ -5,15 +5,12 @@ categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/collections/Sort
|
||||
- functions/collections/Shuffle
|
||||
- functions/collections/Uniq
|
||||
returnType: any
|
||||
signatures: [collections.Reverse COLLECTION]
|
||||
related:
|
||||
- collections.Apply
|
||||
- collections.Delimit
|
||||
- collections.In
|
||||
- collections.Reverse
|
||||
- collections.Seq
|
||||
- collections.Slice
|
||||
aliases: [/functions/collections.reverse]
|
||||
---
|
||||
|
||||
|
@@ -5,18 +5,12 @@ categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [seq]
|
||||
related: []
|
||||
returnType: '[]int'
|
||||
signatures:
|
||||
- collections.Seq LAST
|
||||
- collections.Seq FIRST LAST
|
||||
- collections.Seq FIRST INCREMENT LAST
|
||||
related:
|
||||
- collections.Apply
|
||||
- collections.Delimit
|
||||
- collections.In
|
||||
- collections.Reverse
|
||||
- collections.Seq
|
||||
- collections.Slice
|
||||
aliases: [/functions/seq]
|
||||
---
|
||||
|
||||
@@ -27,7 +21,7 @@ aliases: [/functions/seq]
|
||||
{{ seq -2 2 2 }} → [-2 0 2]
|
||||
```
|
||||
|
||||
Iterate over a sequence of integers:
|
||||
A contrived example of iterating over a sequence of integers:
|
||||
|
||||
```go-html-template
|
||||
{{ $product := 1 }}
|
||||
@@ -37,10 +31,6 @@ Iterate over a sequence of integers:
|
||||
{{ $product }} → 24
|
||||
```
|
||||
|
||||
The example above is contrived. To calculate the product of 2 or more numbers, use the [`math.Product`] function:
|
||||
|
||||
```go-html-template
|
||||
{{ math.Product (seq 4) }} → 24
|
||||
```
|
||||
|
||||
[`math.Product`]: /functions/math/product
|
||||
{{% note %}}
|
||||
The slice created by the `seq` function is limited to 2000 elements.
|
||||
{{% /note %}}
|
||||
|
@@ -5,13 +5,12 @@ categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [shuffle]
|
||||
related:
|
||||
- functions/collections/Reverse
|
||||
- functions/collections/Sort
|
||||
- functions/collections/Uniq
|
||||
returnType: any
|
||||
signatures: [collections.Shuffle COLLECTION]
|
||||
related:
|
||||
- collections.Reverse
|
||||
- collections.Shuffle
|
||||
- collections.Sort
|
||||
- collections.Uniq
|
||||
aliases: [/functions/shuffle]
|
||||
---
|
||||
|
||||
|
@@ -5,16 +5,10 @@ categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [slice]
|
||||
related:
|
||||
- functions/collections/Dictionary
|
||||
returnType: any
|
||||
signatures: [collections.Slice ITEM...]
|
||||
related:
|
||||
- collections.Append
|
||||
- collections.Apply
|
||||
- collections.Delimit
|
||||
- collections.In
|
||||
- collections.Reverse
|
||||
- collections.Seq
|
||||
- collections.Slice
|
||||
aliases: [/functions/slice]
|
||||
---
|
||||
|
||||
|
@@ -5,13 +5,13 @@ categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [sort]
|
||||
related:
|
||||
- functions/collections/Reverse
|
||||
- functions/collections/Shuffle
|
||||
- functions/collections/Uniq
|
||||
returnType: any
|
||||
signatures: ['collections.Sort COLLECTION [KEY] [ORDER]']
|
||||
related:
|
||||
- collections.Reverse
|
||||
- collections.Shuffle
|
||||
- collections.Sort
|
||||
- collections.Uniq
|
||||
toc: true
|
||||
aliases: [/functions/sort]
|
||||
---
|
||||
|
||||
@@ -105,6 +105,40 @@ This produces:
|
||||
Victor Marius Jean
|
||||
```
|
||||
|
||||
### First level key removal
|
||||
|
||||
Hugo removes the first level keys when sorting a map.
|
||||
|
||||
Original map:
|
||||
|
||||
```json
|
||||
{
|
||||
"felix": {
|
||||
"breed": "malicious",
|
||||
"type": "cat"
|
||||
},
|
||||
"spot": {
|
||||
"breed": "boxer",
|
||||
"type": "dog"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
After sorting:
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"breed": "malicious",
|
||||
"type": "cat"
|
||||
},
|
||||
{
|
||||
"breed": "boxer",
|
||||
"type": "dog"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
## Sort a page collection
|
||||
|
||||
{{% note %}}
|
||||
|
@@ -5,13 +5,13 @@ categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [symdiff]
|
||||
related:
|
||||
- functions/collections/Complement
|
||||
- functions/collections/Intersect
|
||||
- functions/collections/SymDiff
|
||||
- functions/collections/Union
|
||||
returnType: any
|
||||
signatures: [COLLECTION | collections.SymDiff COLLECTION]
|
||||
related:
|
||||
- collections.Complement
|
||||
- collections.Intersect
|
||||
- collections.SymDiff
|
||||
- collections.Union
|
||||
aliases: [/functions/symdiff]
|
||||
---
|
||||
|
||||
|
@@ -5,13 +5,13 @@ categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [union]
|
||||
related:
|
||||
- functions/collections/Complement
|
||||
- functions/collections/Intersect
|
||||
- functions/collections/SymDiff
|
||||
- functions/collections/Union
|
||||
returnType: any
|
||||
signatures: [collections.Union SET1 SET2]
|
||||
related:
|
||||
- collections.Complement
|
||||
- collections.Intersect
|
||||
- collections.SymDiff
|
||||
- collections.Union
|
||||
aliases: [/functions/union]
|
||||
---
|
||||
|
||||
|
@@ -5,13 +5,13 @@ categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [uniq]
|
||||
related:
|
||||
- functions/collections/Reverse
|
||||
- functions/collections/Shuffle
|
||||
- functions/collections/Sort
|
||||
- functions/collections/Uniq
|
||||
returnType: any
|
||||
signatures: [collections.Uniq COLLECTION]
|
||||
related:
|
||||
- collections.Reverse
|
||||
- collections.Shuffle
|
||||
- collections.Sort
|
||||
- collections.Uniq
|
||||
aliases: [/functions/uniq]
|
||||
---
|
||||
|
||||
|
@@ -5,16 +5,11 @@ categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [where]
|
||||
related: []
|
||||
returnType: any
|
||||
signatures: ['collections.Where COLLECTION KEY [OPERATOR] VALUE']
|
||||
related:
|
||||
- collections.Dictionary
|
||||
- collections.Group
|
||||
- collections.Index
|
||||
- collections.IsSet
|
||||
- collections.Where
|
||||
aliases: [/functions/where]
|
||||
toc: true
|
||||
aliases: [/functions/where]
|
||||
---
|
||||
|
||||
The `where` function returns the given collection, removing elements that do not satisfy the comparison condition. The comparison condition is comprised of the `KEY`, `OPERATOR`, and `VALUE` arguments:
|
||||
@@ -37,9 +32,10 @@ Hugo will test for equality if you do not provide an `OPERATOR` argument. For ex
|
||||
The where function takes three or four arguments. The `OPERATOR` argument is optional.
|
||||
|
||||
COLLECTION
|
||||
: (`any`) Typically a page collection or a [slice] of [maps].
|
||||
: (`any`) A [page collection] or a [slice] of [maps].
|
||||
|
||||
[maps]: /getting-started/glossary/#map
|
||||
[page collection]: /getting-started/glossary/#page-collection
|
||||
[slice]: /getting-started/glossary/#slice
|
||||
|
||||
KEY
|
||||
@@ -50,7 +46,7 @@ KEY
|
||||
```
|
||||
|
||||
[chain]: /getting-started/glossary/#chain
|
||||
|
||||
Typically a
|
||||
OPERATOR
|
||||
: (`string`) The logical comparison [operator](#operators).
|
||||
|
||||
@@ -64,7 +60,7 @@ Comparison|Result
|
||||
`false "eq" "false"`|`false`
|
||||
`false "eq" false`|`true`
|
||||
|
||||
When one or both of the values to compare is a slice, use the `in`, `not in` or `intersect` operators as described below.
|
||||
When one or both of the values to compare is a slice, use the `in`, `not in`, or `intersect` operators as described below.
|
||||
|
||||
## Operators
|
||||
|
||||
@@ -123,14 +119,14 @@ Compare the value of the given field to an [`int`] or [`float`]:
|
||||
[`float`]: /getting-started/glossary/#float
|
||||
|
||||
```go-html-template
|
||||
{{ $sectionPages := where site.RegularPages "Section" "eq" "books" }}
|
||||
{{ $books := where site.RegularPages "Section" "eq" "books" }}
|
||||
|
||||
{{ $pages := where $sectionPages "Params.price" "eq" 42 }}
|
||||
{{ $pages := where $sectionPages "Params.price" "ne" 42.67 }}
|
||||
{{ $pages := where $sectionPages "Params.price" "ge" 42 }}
|
||||
{{ $pages := where $sectionPages "Params.price" "gt" 42.67 }}
|
||||
{{ $pages := where $sectionPages "Params.price" "le" 42 }}
|
||||
{{ $pages := where $sectionPages "Params.price" "lt" 42.67 }}
|
||||
{{ $pages := where $books "Params.price" "eq" 42 }}
|
||||
{{ $pages := where $books "Params.price" "ne" 42.67 }}
|
||||
{{ $pages := where $books "Params.price" "ge" 42 }}
|
||||
{{ $pages := where $books "Params.price" "gt" 42.67 }}
|
||||
{{ $pages := where $books "Params.price" "le" 42 }}
|
||||
{{ $pages := where $books "Params.price" "lt" 42.67 }}
|
||||
```
|
||||
|
||||
## Boolean comparison
|
||||
@@ -140,12 +136,12 @@ Compare the value of the given field to a [`bool`]:
|
||||
[`bool`]: /getting-started/glossary/#bool
|
||||
|
||||
```go-html-template
|
||||
{{ $sectionPages := where site.RegularPages "Section" "eq" "books" }}
|
||||
{{ $books := where site.RegularPages "Section" "eq" "books" }}
|
||||
|
||||
{{ $pages := where $sectionPages "Params.fiction" "eq" true }}
|
||||
{{ $pages := where $sectionPages "Params.fiction" "eq" false }}
|
||||
{{ $pages := where $sectionPages "Params.fiction" "ne" true }}
|
||||
{{ $pages := where $sectionPages "Params.fiction" "ne" false }}
|
||||
{{ $pages := where $books "Params.fiction" "eq" true }}
|
||||
{{ $pages := where $books "Params.fiction" "eq" false }}
|
||||
{{ $pages := where $books "Params.fiction" "ne" true }}
|
||||
{{ $pages := where $books "Params.fiction" "ne" false }}
|
||||
```
|
||||
|
||||
## Member comparison
|
||||
@@ -158,19 +154,19 @@ Compare a [`scalar`] to a [`slice`].
|
||||
For example, to return a collection of pages where the `color` page parameter is either "red" or "yellow":
|
||||
|
||||
```go-html-template
|
||||
{{ $sectionPages := where site.RegularPages "Section" "eq" "fruit" }}
|
||||
{{ $fruit := where site.RegularPages "Section" "eq" "fruit" }}
|
||||
|
||||
{{ $colors := slice "red" "yellow" }}
|
||||
{{ $pages := where $sectionPages "Params.color" "in" $colors }}
|
||||
{{ $pages := where $fruit "Params.color" "in" $colors }}
|
||||
```
|
||||
|
||||
To return a collection of pages where the "color" page parameter is neither "red" nor "yellow":
|
||||
|
||||
```go-html-template
|
||||
{{ $sectionPages := where site.RegularPages "Section" "eq" "fruit" }}
|
||||
{{ $fruit := where site.RegularPages "Section" "eq" "fruit" }}
|
||||
|
||||
{{ $colors := slice "red" "yellow" }}
|
||||
{{ $pages := where $sectionPages "Params.color" "not in" $colors }}
|
||||
{{ $pages := where $fruit "Params.color" "not in" $colors }}
|
||||
```
|
||||
|
||||
## Intersection comparison
|
||||
@@ -180,10 +176,10 @@ Compare a [`slice`] to a [`slice`], returning collection elements with common va
|
||||
For example, to return a collection of pages where any of the terms in the "genres" taxonomy are "suspense" or "romance":
|
||||
|
||||
```go-html-template
|
||||
{{ $sectionPages := where site.RegularPages "Section" "eq" "books" }}
|
||||
{{ $books := where site.RegularPages "Section" "eq" "books" }}
|
||||
|
||||
{{ $genres := slice "suspense" "romance" }}
|
||||
{{ $pages := where $sectionPages "Params.genres" "intersect" $genres }}
|
||||
{{ $pages := where $books "Params.genres" "intersect" $genres }}
|
||||
```
|
||||
|
||||
## Regular expression comparison
|
||||
|
Reference in New Issue
Block a user