diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-12-02 09:19:23 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-12-02 09:19:23 +0100 |
commit | ef518485cec947464509d290e6edb237c833c379 (patch) | |
tree | 32761983e311e4c3f8498d7dc385449ae627b386 /docs/content/en/functions | |
parent | 83080df61104089789272b429d00fa1e2d658598 (diff) | |
parent | da16527896d3087585c5e758083ea498dcabc2c3 (diff) |
Merge commit 'da16527896d3087585c5e758083ea498dcabc2c3'
Diffstat (limited to 'docs/content/en/functions')
22 files changed, 168 insertions, 21 deletions
diff --git a/docs/content/en/functions/abslangurl.md b/docs/content/en/functions/abslangurl.md index 11d540bde..2e1996f7e 100644 --- a/docs/content/en/functions/abslangurl.md +++ b/docs/content/en/functions/abslangurl.md @@ -55,6 +55,7 @@ With `baseURL = https://example.org/docs/` {{ absLangURL "/" }} → https://example.org/en/ {{ absLangURL "/articles" }} → https://example.org/en/articles {{ absLangURL "/style.css" }} → https://example.org/en/style.css +``` {{% note %}} The last three examples are not desirable in most situations. As a best practice, never include a leading slash when using this function. diff --git a/docs/content/en/functions/chomp.md b/docs/content/en/functions/chomp.md index c56505c2c..3e61c8db5 100644 --- a/docs/content/en/functions/chomp.md +++ b/docs/content/en/functions/chomp.md @@ -10,7 +10,9 @@ menu: docs: parent: "functions" keywords: [trim] -signature: ["chomp INPUT"] +signature: + - "chomp INPUT" + - "strings.Chomp INPUT" workson: [] hugoversion: relatedfuncs: [truncate] diff --git a/docs/content/en/functions/countrunes.md b/docs/content/en/functions/countrunes.md index 0acef095b..01ded4d6f 100644 --- a/docs/content/en/functions/countrunes.md +++ b/docs/content/en/functions/countrunes.md @@ -9,7 +9,9 @@ menu: docs: parent: "functions" keywords: [counting, word count] -signature: ["countrunes INPUT"] +signature: + - "countrunes INPUT" + - "strings.CountRunes INPUT" workson: [] hugoversion: relatedfuncs: [] diff --git a/docs/content/en/functions/crypto.FNV32a.md b/docs/content/en/functions/crypto.FNV32a.md new file mode 100644 index 000000000..dddf7a9aa --- /dev/null +++ b/docs/content/en/functions/crypto.FNV32a.md @@ -0,0 +1,15 @@ +--- +title: crypto.FNV32a +description: Returns the FNV (Fowler–Noll–Vo) 32 bit hash of a given string. +categories: [functions] +menu: + docs: + parent: "functions" +keywords: [crypto hash FNV32 Fowler-Noll-Vo] +signature: ["crypto.FNV32a STRING"] +aliases: [] +--- + +This function calculates the 32 bit [FNV1a hash](https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function#FNV-1a_hash) of a given string according to the [specification](https://datatracker.ietf.org/doc/html/draft-eastlake-fnv-12): + + {{ crypto.FNV32a "Hello world" }} → 1498229191 diff --git a/docs/content/en/functions/dateformat.md b/docs/content/en/functions/dateformat.md index 7a16e80b2..210913b87 100644 --- a/docs/content/en/functions/dateformat.md +++ b/docs/content/en/functions/dateformat.md @@ -9,7 +9,9 @@ menu: docs: parent: "functions" keywords: [dates,time,strings] -signature: ["time.Format LAYOUT INPUT"] +signature: + - "time.Format LAYOUT INPUT" + - "dateFormat LAYOUT INPUT" workson: [] hugoversion: relatedfuncs: [Format,now,Unix,time] diff --git a/docs/content/en/functions/duration.md b/docs/content/en/functions/duration.md new file mode 100644 index 000000000..bf771c0a9 --- /dev/null +++ b/docs/content/en/functions/duration.md @@ -0,0 +1,32 @@ +--- +title: duration +description: Returns a `time.Duration` structure, using the given time unit and duration number. +categories: [functions] +menu: + docs: + parent: "functions" +keywords: [time duration] +signature: ["duration TIME_UNIT DURATION_NUMBER"] +aliases: [] +--- + +`time.Duration` converts a given number into a [`time.Duration`](https://pkg.go.dev/time#Duration) structure so you can access its fields. E.g. you can perform [time operations](https://pkg.go.dev/time#Duration) on the returned `time.Duration` value: + + {{ printf "There are %.0f seconds in one day." (duration "hour" 24).Seconds }} + <!-- Output: There are 86400 seconds in one day. --> + +Make your code simpler to understand by using a [chained pipeline](https://pkg.go.dev/text/template#hdr-Pipelines): + + {{ mul 7.75 60 | duration "minute" }} → 7h45m0s + {{ mul 120 60 | mul 1000 | duration "millisecond" }} → 2h0m0s + +You have to specify a time unit for the number given to the function. Valid time units are: + +Duration|Valid time units +:--|:-- +hours|`hour`, `h` +minutes|`minute`, `m` +seconds|`second`, `s` +milliseconds|`millisecond`, `ms` +microseconds|`microsecond`, `us`, `µs` +nanoseconds|`nanosecond`, `ns` diff --git a/docs/content/en/functions/emojify.md b/docs/content/en/functions/emojify.md index 20e30fafa..a323470b7 100644 --- a/docs/content/en/functions/emojify.md +++ b/docs/content/en/functions/emojify.md @@ -16,7 +16,7 @@ relatedfuncs: [] deprecated: false --- -`emoji` runs a passed string through the Emoji emoticons processor. +`emojify` runs a passed string through the Emoji emoticons processor. See the [Emoji cheat sheet][emojis] for available emoticons. diff --git a/docs/content/en/functions/findRe.md b/docs/content/en/functions/findRe.md index 2896e3cd1..8e08bfc0d 100644 --- a/docs/content/en/functions/findRe.md +++ b/docs/content/en/functions/findRe.md @@ -12,7 +12,7 @@ signature: relatedfuncs: [replaceRE] aliases: [] --- -By default, the `findRE` function finds all matches. You can limit the number of matches with an optional LIMIT paramater. +By default, the `findRE` function finds all matches. You can limit the number of matches with an optional LIMIT parameter. When specifying the regular expression, use a raw [string literal] (backticks) instead of an interpreted string literal (double quotes) to simplify the syntax. With an interpreted string literal you must escape backslashes. diff --git a/docs/content/en/functions/i18n.md b/docs/content/en/functions/i18n.md index 34a6ff022..8f8c9642c 100644 --- a/docs/content/en/functions/i18n.md +++ b/docs/content/en/functions/i18n.md @@ -10,7 +10,10 @@ menu: docs: parent: "functions" keywords: [internationalization,i18n,multilingual] -signature: ["i18n KEY", "T KEY"] +signature: + - "i18n KEY" + - "T KEY" + - "lang.Translate KEY" workson: [] hugoversion: relatedfuncs: [] diff --git a/docs/content/en/functions/lower.md b/docs/content/en/functions/lower.md index 0e8ba6c6d..3fbfc919b 100644 --- a/docs/content/en/functions/lower.md +++ b/docs/content/en/functions/lower.md @@ -10,7 +10,9 @@ menu: docs: parent: "functions" keywords: [strings,casing] -signature: ["lower INPUT"] +signature: + - "lower INPUT" + - "strings.ToLower INPUT" workson: [] hugoversion: relatedfuncs: [] @@ -18,6 +20,10 @@ deprecated: false aliases: [] --- -``` -{{lower "BatMan"}} → "batman" + +Note that `lower` can be applied in your templates in more than one way: + +```go-html-template +{{ lower "BatMan" }} → "batman" +{{ "BatMan" | lower }} → "batman" ``` diff --git a/docs/content/en/functions/replace.md b/docs/content/en/functions/replace.md index 07b83d035..36e392015 100644 --- a/docs/content/en/functions/replace.md +++ b/docs/content/en/functions/replace.md @@ -8,11 +8,13 @@ categories: [functions] menu: docs: parent: "functions" -keywords: [] -signature: ["strings.Replace INPUT OLD NEW [LIMIT]", "replace INPUT OLD NEW [LIMIT]"] +keywords: [replace] +signature: + - "replace INPUT OLD NEW [LIMIT]" + - "strings.Replace INPUT OLD NEW [LIMIT]" workson: [] hugoversion: -relatedfuncs: [] +relatedfuncs: [replaceRE] deprecated: false aliases: [] --- diff --git a/docs/content/en/functions/replacere.md b/docs/content/en/functions/replacere.md index f1e34ba65..cc4eb5dc2 100644 --- a/docs/content/en/functions/replacere.md +++ b/docs/content/en/functions/replacere.md @@ -5,14 +5,14 @@ categories: [functions] menu: docs: parent: functions -keywords: [regex] +keywords: [replace regex] signature: - "replaceRE PATTERN REPLACEMENT INPUT [LIMIT]" - "strings.ReplaceRE PATTERN REPLACEMENT INPUT [LIMIT]" -relatedfuncs: [findRE] +relatedfuncs: [replace,findRE] aliases: [] --- -By default, the `replaceRE` function replaces all matches. You can limit the number of matches with an optional LIMIT paramater. +By default, the `replaceRE` function replaces all matches. You can limit the number of matches with an optional LIMIT parameter. When specifying the regular expression, use a raw [string literal] (backticks) instead of an interpreted string literal (double quotes) to simplify the syntax. With an interpreted string literal you must escape backslashes. diff --git a/docs/content/en/functions/slicestr.md b/docs/content/en/functions/slicestr.md index 254ad9a61..8164f2720 100644 --- a/docs/content/en/functions/slicestr.md +++ b/docs/content/en/functions/slicestr.md @@ -10,7 +10,9 @@ menu: docs: parent: "functions" keywords: [strings] -signature: ["slicestr STRING START [END]"] +signature: + - "slicestr STRING START [END]" + - "strings.SliceString STRING START [END]" workson: [] hugoversion: relatedfuncs: [] diff --git a/docs/content/en/functions/strings.Contains.md b/docs/content/en/functions/strings.Contains.md new file mode 100644 index 000000000..8ebd9ad33 --- /dev/null +++ b/docs/content/en/functions/strings.Contains.md @@ -0,0 +1,18 @@ +--- +title: strings.Contains +description: Reports whether a string contains a substring. +categories: [functions] +menu: + docs: + parent: "functions" +keywords: [string strings substring contains] +signature: ["strings.Contains STRING SUBSTRING"] +aliases: [] +relatedfuncs: [strings.ContainsAny] +--- + + {{ strings.Contains "Hugo" "go" }} → true + +The check is case sensitive: + + {{ strings.Contains "Hugo" "Go" }} → false diff --git a/docs/content/en/functions/strings.ContainsAny.md b/docs/content/en/functions/strings.ContainsAny.md new file mode 100644 index 000000000..bfbc2242b --- /dev/null +++ b/docs/content/en/functions/strings.ContainsAny.md @@ -0,0 +1,18 @@ +--- +title: strings.ContainsAny +description: Reports whether a string contains any character from a given string. +categories: [functions] +menu: + docs: + parent: "functions" +keywords: [string strings substring contains any] +signature: ["strings.ContainsAny STRING CHARACTERS"] +aliases: [] +relatedfuncs: [strings.Contains] +--- + + {{ strings.ContainsAny "Hugo" "gm" }} → true + +The check is case sensitive: + + {{ strings.ContainsAny "Hugo" "Gm" }} → false diff --git a/docs/content/en/functions/strings.FirstUpper.md b/docs/content/en/functions/strings.FirstUpper.md new file mode 100644 index 000000000..b97d00f29 --- /dev/null +++ b/docs/content/en/functions/strings.FirstUpper.md @@ -0,0 +1,14 @@ +--- +title: strings.FirstUpper +description: Capitalizes the first character of a given string. +categories: [functions] +menu: + docs: + parent: "functions" +keywords: [strings capitalize uppercase first] +signature: ["strings.FirstUpper STRING"] +hugoversion: +aliases: [] +--- + + {{ strings.FirstUpper "foo" }} → "Foo" diff --git a/docs/content/en/functions/substr.md b/docs/content/en/functions/substr.md index 31f733e0b..4a00b6eb1 100644 --- a/docs/content/en/functions/substr.md +++ b/docs/content/en/functions/substr.md @@ -11,7 +11,9 @@ menu: parent: "functions" keywords: [strings] aliases: [] -signature: ["substr STRING START [LENGTH]"] +signature: + - "substr STRING START [LENGTH]" + - "strings.Substr STRING START [LENGTH]" workson: [] hugoversion: relatedfuncs: [] diff --git a/docs/content/en/functions/time.ParseDuration.md b/docs/content/en/functions/time.ParseDuration.md new file mode 100644 index 000000000..aabba601a --- /dev/null +++ b/docs/content/en/functions/time.ParseDuration.md @@ -0,0 +1,20 @@ +--- +title: time.ParseDuration +description: Parses a given duration string into a `time.Duration` structure. +categories: [functions] +menu: + docs: + parent: "functions" +keywords: [time parse duration] +signature: ["time.ParseDuration DURATION"] +hugoversion: +aliases: [] +--- + +`time.ParseDuration` parses a duration string into a [`time.Duration`](https://pkg.go.dev/time#Duration) structure so you can access its fields. +A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as `300ms`, `-1.5h` or `2h45m`. Valid time units are `ns`, `us` (or `µs`), `ms`, `s`, `m`, `h`. + +You can perform [time operations](https://pkg.go.dev/time#Duration) on the returned `time.Duration` value: + + {{ printf "There are %.0f seconds in one day." (time.ParseDuration "24h").Seconds }} + <!-- Output: There are 86400 seconds in one day. --> diff --git a/docs/content/en/functions/title.md b/docs/content/en/functions/title.md index 201e4c140..6c87d69ac 100644 --- a/docs/content/en/functions/title.md +++ b/docs/content/en/functions/title.md @@ -10,7 +10,9 @@ menu: docs: parent: "functions" keywords: [strings] -signature: ["title INPUT"] +signature: + - "title INPUT" + - "strings.Title INPUT" workson: [] hugoversion: relatedfuncs: [] diff --git a/docs/content/en/functions/trim.md b/docs/content/en/functions/trim.md index 7945ffef9..fec435ec7 100644 --- a/docs/content/en/functions/trim.md +++ b/docs/content/en/functions/trim.md @@ -10,7 +10,9 @@ menu: docs: parent: "functions" keywords: [strings] -signature: ["trim INPUT CUTSET"] +signature: + - "trim INPUT CUTSET" + - "strings.Trim INPUT CUTSET" workson: [] hugoversion: relatedfuncs: [] diff --git a/docs/content/en/functions/truncate.md b/docs/content/en/functions/truncate.md index 8d0dd36b1..54cfb3612 100644 --- a/docs/content/en/functions/truncate.md +++ b/docs/content/en/functions/truncate.md @@ -10,7 +10,9 @@ menu: docs: parent: "functions" keywords: [strings] -signature: ["truncate SIZE INPUT", "truncate SIZE ELLIPSIS INPUT"] +signature: + - "truncate SIZE [ELLIPSIS] INPUT" + - "strings.Truncate SIZE [ELLIPSIS] INPUT" workson: [] hugoversion: 19 relatedfuncs: [] diff --git a/docs/content/en/functions/upper.md b/docs/content/en/functions/upper.md index c7d523217..02f4cd578 100644 --- a/docs/content/en/functions/upper.md +++ b/docs/content/en/functions/upper.md @@ -11,7 +11,9 @@ menu: docs: parent: "functions" toc: -signature: ["upper INPUT"] +signature: + - "upper INPUT" + - "strings.ToUpper INPUT" workson: [] hugoversion: relatedfuncs: [] |