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:
Andreas Deininger 2022-11-22 16:40:31 +01:00 committed by GitHub
parent 372bf5e88b
commit ce60bb5729
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 115 additions and 4 deletions

View File

@ -0,0 +1,15 @@
---
title: crypto.FNV32a
description: Returns the FNV (FowlerNollVo) 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

View 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`

View File

@ -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"
```

View 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

View 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

View 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. -->

View File

@ -11,7 +11,9 @@ menu:
docs:
parent: "functions"
toc:
signature: ["upper INPUT"]
signature:
- "upper INPUT"
- "strings.ToUpper INPUT"
workson: []
hugoversion:
relatedfuncs: []