mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-17 14:45:11 -04:00
Change code blocks from indented to fenced
This commit is contained in:
parent
cfab978e67
commit
8d634ac701
@ -20,13 +20,17 @@ signature:
|
||||
|
||||
`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. -->
|
||||
```go-html-template
|
||||
{{ 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
|
||||
```go-html-template
|
||||
{{ 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:
|
||||
|
||||
|
@ -16,7 +16,6 @@ relatedFuncs:
|
||||
signature:
|
||||
- crypto.MD5 INPUT
|
||||
- md5 INPUT
|
||||
|
||||
---
|
||||
|
||||
```go-html-template
|
||||
|
@ -16,7 +16,6 @@ relatedFuncs:
|
||||
signature:
|
||||
- time.Now
|
||||
- now
|
||||
|
||||
---
|
||||
|
||||
See [`time.Time`](https://godoc.org/time#Time).
|
||||
|
@ -10,7 +10,6 @@ namespace:
|
||||
relatedFuncs: []
|
||||
signature:
|
||||
- .Param KEY
|
||||
|
||||
---
|
||||
|
||||
The `.Param` method on `.Page` looks for the given `KEY` in page parameters, and returns the corresponding value. If it cannot find the `KEY` in page parameters, it looks for the `KEY` in site parameters. If it cannot find the `KEY` in either location, the `.Param` method returns `nil`.
|
||||
|
@ -12,7 +12,6 @@ relatedFuncs:
|
||||
- reflect.IsSlice
|
||||
signature:
|
||||
- reflect.IsSlice INPUT
|
||||
|
||||
---
|
||||
|
||||
`reflect.IsSlice` reports if `VALUE` is a slice. Returns a boolean.
|
||||
|
@ -16,7 +16,6 @@ relatedFuncs:
|
||||
signature:
|
||||
- safe.HTML INPUT
|
||||
- safeHTML INPUT
|
||||
|
||||
---
|
||||
|
||||
It should not be used for HTML from a third-party, or HTML with unclosed tags or comments.
|
||||
|
@ -18,8 +18,11 @@ signature:
|
||||
- strings.Contains STRING SUBSTRING
|
||||
---
|
||||
|
||||
{{ strings.Contains "Hugo" "go" }} → true
|
||||
|
||||
```go-html-template
|
||||
{{ strings.Contains "Hugo" "go" }} → true
|
||||
```
|
||||
The check is case sensitive:
|
||||
|
||||
{{ strings.Contains "Hugo" "Go" }} → false
|
||||
```go-html-template
|
||||
{{ strings.Contains "Hugo" "Go" }} → false
|
||||
```
|
||||
|
@ -16,11 +16,14 @@ relatedFuncs:
|
||||
- collections.In
|
||||
signature:
|
||||
- strings.ContainsAny STRING CHARACTERS
|
||||
|
||||
---
|
||||
|
||||
{{ strings.ContainsAny "Hugo" "gm" }} → true
|
||||
```go-html-template
|
||||
{{ strings.ContainsAny "Hugo" "gm" }} → true
|
||||
---
|
||||
|
||||
The check is case sensitive:
|
||||
|
||||
{{ strings.ContainsAny "Hugo" "Gm" }} → false
|
||||
```go-html-template
|
||||
{{ strings.ContainsAny "Hugo" "Gm" }} → false
|
||||
```
|
||||
|
@ -16,13 +16,16 @@ relatedFuncs:
|
||||
- strings.TrimSuffix
|
||||
signature:
|
||||
- strings.TrimLeft CUTSET STRING
|
||||
|
||||
---
|
||||
|
||||
Given the string `"abba"`, leading `"a"`'s can be removed a follows:
|
||||
|
||||
{{ strings.TrimLeft "a" "abba" }} → "bba"
|
||||
```go-html-template
|
||||
{{ strings.TrimLeft "a" "abba" }} → "bba"
|
||||
```
|
||||
|
||||
Numbers can be handled as well:
|
||||
|
||||
{{ strings.TrimLeft 12 1221341221 }} → "341221"
|
||||
```go-html-template
|
||||
{{ strings.TrimLeft 12 1221341221 }} → "341221"
|
||||
```
|
||||
|
@ -20,6 +20,8 @@ signature:
|
||||
|
||||
Given the string `"aabbaa"`, the specified prefix is only removed if `"aabbaa"` starts with it:
|
||||
|
||||
{{ strings.TrimPrefix "a" "aabbaa" }} → "abbaa"
|
||||
{{ strings.TrimPrefix "aa" "aabbaa" }} → "bbaa"
|
||||
{{ strings.TrimPrefix "aaa" "aabbaa" }} → "aabbaa"
|
||||
```go-html-template
|
||||
{{ strings.TrimPrefix "a" "aabbaa" }} → "abbaa"
|
||||
{{ strings.TrimPrefix "aa" "aabbaa" }} → "bbaa"
|
||||
{{ strings.TrimPrefix "aaa" "aabbaa" }} → "aabbaa"
|
||||
```
|
||||
|
@ -20,8 +20,12 @@ signature:
|
||||
|
||||
Given the string `"abba"`, trailing `"a"`'s can be removed a follows:
|
||||
|
||||
{{ strings.TrimRight "a" "abba" }} → "abb"
|
||||
```go-html-template
|
||||
{{ strings.TrimRight "a" "abba" }} → "abb"
|
||||
```
|
||||
|
||||
Numbers can be handled as well:
|
||||
|
||||
{{ strings.TrimRight 12 1221341221 }} → "122134"
|
||||
```go-html-template
|
||||
{{ strings.TrimRight 12 1221341221 }} → "122134"
|
||||
```
|
||||
|
@ -20,6 +20,8 @@ signature:
|
||||
|
||||
Given the string `"aabbaa"`, the specified suffix is only removed if `"aabbaa"` ends with it:
|
||||
|
||||
{{ strings.TrimSuffix "a" "aabbaa" }} → "aabba"
|
||||
{{ strings.TrimSuffix "aa" "aabbaa" }} → "aabb"
|
||||
{{ strings.TrimSuffix "aaa" "aabbaa" }} → "aabbaa"
|
||||
```go-html-template
|
||||
{{ strings.TrimSuffix "a" "aabbaa" }} → "aabba"
|
||||
{{ strings.TrimSuffix "aa" "aabbaa" }} → "aabb"
|
||||
{{ strings.TrimSuffix "aaa" "aabbaa" }} → "aabbaa"
|
||||
```
|
||||
|
@ -10,7 +10,6 @@ namespace: templates
|
||||
relatedFuncs: []
|
||||
signature:
|
||||
- templates.Exists PATH
|
||||
|
||||
---
|
||||
|
||||
A template file is any file living below the `layouts` directories of either the project or any of its theme components including partials and shortcodes.
|
||||
|
@ -22,5 +22,7 @@ A duration string is a possibly signed sequence of decimal numbers, each with op
|
||||
|
||||
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. -->
|
||||
```go-html-template
|
||||
{{ printf "There are %.0f seconds in one day." (time.ParseDuration "24h").Seconds }}
|
||||
<!-- Output: There are 86400 seconds in one day. -->
|
||||
```
|
||||
|
Loading…
x
Reference in New Issue
Block a user