diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2024-01-26 08:22:42 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2024-01-26 08:22:42 +0100 |
commit | 3758456b31695dd59ebe5eb35b19c1b054287a48 (patch) | |
tree | a6391bec1ee0247632cb5bf526175bb1defba804 /docs/content/en/functions | |
parent | d0d2c6795e0870bf96d167700a475737a17ea005 (diff) | |
parent | 7125ad401ad043e46262afc7eca8dceb6d54bb9e (diff) |
Merge commit '7125ad401ad043e46262afc7eca8dceb6d54bb9e'
Diffstat (limited to 'docs/content/en/functions')
46 files changed, 215 insertions, 174 deletions
diff --git a/docs/content/en/functions/collections/Append.md b/docs/content/en/functions/collections/Append.md index 5632dccfb..cb29dc2f2 100644 --- a/docs/content/en/functions/collections/Append.md +++ b/docs/content/en/functions/collections/Append.md @@ -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]] ``` diff --git a/docs/content/en/functions/collections/Apply.md b/docs/content/en/functions/collections/Apply.md index abd6fca77..9153e546a 100644 --- a/docs/content/en/functions/collections/Apply.md +++ b/docs/content/en/functions/collections/Apply.md @@ -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] --- diff --git a/docs/content/en/functions/collections/Delimit.md b/docs/content/en/functions/collections/Delimit.md index 6aea467ee..b85059d4b 100644 --- a/docs/content/en/functions/collections/Delimit.md +++ b/docs/content/en/functions/collections/Delimit.md @@ -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]'] diff --git a/docs/content/en/functions/collections/Dictionary.md b/docs/content/en/functions/collections/Dictionary.md index 2e933aca9..f46b02e75 100644 --- a/docs/content/en/functions/collections/Dictionary.md +++ b/docs/content/en/functions/collections/Dictionary.md @@ -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] diff --git a/docs/content/en/functions/collections/First.md b/docs/content/en/functions/collections/First.md index 49a0362f5..cb2397af1 100644 --- a/docs/content/en/functions/collections/First.md +++ b/docs/content/en/functions/collections/First.md @@ -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] diff --git a/docs/content/en/functions/collections/Group.md b/docs/content/en/functions/collections/Group.md index 74aa869df..2f5a333c0 100644 --- a/docs/content/en/functions/collections/Group.md +++ b/docs/content/en/functions/collections/Group.md @@ -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] diff --git a/docs/content/en/functions/collections/In.md b/docs/content/en/functions/collections/In.md index a3ec83d9b..131c0abcf 100644 --- a/docs/content/en/functions/collections/In.md +++ b/docs/content/en/functions/collections/In.md @@ -6,7 +6,6 @@ keywords: [] action: aliases: [in] related: - - functions/collections/Slice - functions/strings/Contains - functions/strings/ContainsAny - functions/strings/ContainsNonSpace diff --git a/docs/content/en/functions/collections/IndexFunction.md b/docs/content/en/functions/collections/IndexFunction.md index e595d2b41..6482884fd 100644 --- a/docs/content/en/functions/collections/IndexFunction.md +++ b/docs/content/en/functions/collections/IndexFunction.md @@ -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 diff --git a/docs/content/en/functions/collections/IsSet.md b/docs/content/en/functions/collections/IsSet.md index 76b336ae3..62b81b712 100644 --- a/docs/content/en/functions/collections/IsSet.md +++ b/docs/content/en/functions/collections/IsSet.md @@ -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 diff --git a/docs/content/en/functions/collections/NewScratch.md b/docs/content/en/functions/collections/NewScratch.md index 793b2b4b5..96f85a8d0 100644 --- a/docs/content/en/functions/collections/NewScratch.md +++ b/docs/content/en/functions/collections/NewScratch.md @@ -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 }} diff --git a/docs/content/en/functions/collections/Querify.md b/docs/content/en/functions/collections/Querify.md index e195c417f..ea0434fc5 100644 --- a/docs/content/en/functions/collections/Querify.md +++ b/docs/content/en/functions/collections/Querify.md @@ -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] --- diff --git a/docs/content/en/functions/collections/Reverse.md b/docs/content/en/functions/collections/Reverse.md index 12c964c76..d0a449763 100644 --- a/docs/content/en/functions/collections/Reverse.md +++ b/docs/content/en/functions/collections/Reverse.md @@ -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] --- diff --git a/docs/content/en/functions/collections/Seq.md b/docs/content/en/functions/collections/Seq.md index e7430e0d0..b572bd7c0 100644 --- a/docs/content/en/functions/collections/Seq.md +++ b/docs/content/en/functions/collections/Seq.md @@ -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 %}} diff --git a/docs/content/en/functions/collections/Shuffle.md b/docs/content/en/functions/collections/Shuffle.md index 18b8cc664..0f28eb4d8 100644 --- a/docs/content/en/functions/collections/Shuffle.md +++ b/docs/content/en/functions/collections/Shuffle.md @@ -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] --- diff --git a/docs/content/en/functions/collections/Slice.md b/docs/content/en/functions/collections/Slice.md index e24b394ca..56c068d4b 100644 --- a/docs/content/en/functions/collections/Slice.md +++ b/docs/content/en/functions/collections/Slice.md @@ -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] --- diff --git a/docs/content/en/functions/collections/Sort.md b/docs/content/en/functions/collections/Sort.md index 6b9ea2c34..2277f883c 100644 --- a/docs/content/en/functions/collections/Sort.md +++ b/docs/content/en/functions/collections/Sort.md @@ -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 %}} diff --git a/docs/content/en/functions/collections/SymDiff.md b/docs/content/en/functions/collections/SymDiff.md index 828c10ce5..7eba3ef42 100644 --- a/docs/content/en/functions |