mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-07 00:54:35 -04:00
Add docu for undocumented functions (#1907)
* Document string manipulation functions * Document crypto.FNV32a function * Document functions duration and time.ParseDuration * Changes according to review feedback
This commit is contained in:
parent
372bf5e88b
commit
ce60bb5729
15
content/en/functions/crypto.FNV32a.md
Normal file
15
content/en/functions/crypto.FNV32a.md
Normal file
@ -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
|
32
content/en/functions/duration.md
Normal file
32
content/en/functions/duration.md
Normal file
@ -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`
|
@ -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"
|
||||
```
|
||||
|
18
content/en/functions/strings.Contains.md
Normal file
18
content/en/functions/strings.Contains.md
Normal file
@ -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
|
18
content/en/functions/strings.ContainsAny.md
Normal file
18
content/en/functions/strings.ContainsAny.md
Normal file
@ -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
|
20
content/en/functions/time.ParseDuration.md
Normal file
20
content/en/functions/time.ParseDuration.md
Normal file
@ -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. -->
|
@ -11,7 +11,9 @@ menu:
|
||||
docs:
|
||||
parent: "functions"
|
||||
toc:
|
||||
signature: ["upper INPUT"]
|
||||
signature:
|
||||
- "upper INPUT"
|
||||
- "strings.ToUpper INPUT"
|
||||
workson: []
|
||||
hugoversion:
|
||||
relatedfuncs: []
|
||||
|
Loading…
x
Reference in New Issue
Block a user