Merge commit 'e509cac533600cf4fa8382c9cdab78ddd82db688'

This commit is contained in:
Bjørn Erik Pedersen
2023-10-20 09:43:56 +02:00
298 changed files with 4568 additions and 1991 deletions

View File

@@ -0,0 +1,33 @@
---
title: fmt.Errorf
linkTitle: errorf
description: Log an ERROR from a template.
categories: [functions]
keywords: []
menu:
docs:
parent: functions
function:
aliases: [errorf]
returnType: string
signatures: ['fmt.Errorf FORMAT [INPUT]']
relatedFunctions:
- fmt.Errorf
- fmt.Erroridf
- fmt.Warnf
aliases: [/functions/errorf]
---
The documentation for [Go's fmt package] describes the structure and content of the format string.
Like the [`printf`] function, the `errorf` function evaluates the format string. It then prints the result to the ERROR log and fails the build. Hugo prints each unique message once to avoid flooding the log with duplicate errors.
```go-html-template
{{ errorf "The %q shortcode requires a src parameter. See %s" .Name .Position }}
```
Use the [`erroridf`] function to allow optional suppression of specific errors.
[`erroridf`]: /functions/fmt/erroridf
[`printf`]: /functions/fmt/printf
[Go's fmt package]: https://pkg.go.dev/fmt

View File

@@ -0,0 +1,48 @@
---
title: fmt.Erroridf
linkTitle: erroridf
description: Log a suppressable ERROR from a template.
categories: [functions]
keywords: []
menu:
docs:
parent: functions
function:
aliases: [erroridf]
returnType: string
signatures: ['fmt.Erroridf ID FORMAT [INPUT]']
relatedFunctions:
- fmt.Errorf
- fmt.Erroridf
- fmt.Warnf
aliases: [/functions/erroridf]
---
The documentation for [Go's fmt package] describes the structure and content of the format string.
Like the [`errorf`] function, the `erroridf` function evaluates the format string, prints the result to the ERROR log, then fails the build. Hugo prints each unique message once to avoid flooding the log with duplicate errors.
Unlike the `errorf` function, you may suppress errors logged by the `erroridf` function by adding the message ID to the `ignoreErrors` array in your site configuration.
This template code:
```go-html-template
{{ erroridf "error-42" "You should consider fixing this." }}
```
Produces this console log:
```text
ERROR You should consider fixing this.
If you feel that this should not be logged as an ERROR, you can ignore it by adding this to your site config:
ignoreErrors = ["error-42"]
```
To suppress this message:
{{< code-toggle file=hugo copy=false >}}
ignoreErrors = ["error-42"]
{{< /code-toggle >}}
[`errorf`]: /functions/fmt/errorf
[Go's fmt package]: https://pkg.go.dev/fmt

View File

@@ -0,0 +1,25 @@
---
title: fmt.Print
linkTitle: print
description: Prints the default representation of the given arguments using the standard `fmt.Print` function.
categories: [functions]
keywords: []
menu:
docs:
parent: functions
function:
aliases: [print]
returnType: string
signatures: [fmt.Print INPUT]
relatedFunctions:
- fmt.Print
- fmt.Printf
- fmt.Println
aliases: [/functions/print]
---
```go-html-template
{{ print "foo" }} → "foo"
{{ print "foo" "bar" }} → "foobar"
{{ print (slice 1 2 3) }} → [1 2 3]
```

View File

@@ -0,0 +1,46 @@
---
title: fmt.Printf
linkTitle: printf
description: Formats a string using the standard `fmt.Sprintf` function.
categories: [functions]
keywords: []
menu:
docs:
parent: functions
function:
aliases: [printf]
returnType: string
signatures: ['fmt.Printf FORMAT [INPUT]']
relatedFunctions:
- fmt.Print
- fmt.Printf
- fmt.Println
aliases: [/functions/printf]
---
The documentation for [Go's fmt package] describes the structure and content of the format string.
[Go's fmt package]: https://pkg.go.dev/fmt
```go-html-template
{{ $var := "world" }}
{{ printf "Hello %s." $var }} → Hello world.
```
```go-html-template
{{ $pi := 3.14159265 }}
{{ printf "Pi is approximately %.2f." $pi }} → 3.14
```
Use the `printf` function with the `safeHTMLAttr` function:
```go-html-template
{{ $desc := "Eat at Joe's" }}
<meta name="description" {{ printf "content=%q" $desc | safeHTMLAttr }}>
```
Hugo renders this to:
```html
<meta name="description" content="Eat at Joe's">
```

View File

@@ -0,0 +1,23 @@
---
title: fmt.Println
linkTitle: println
description: Prints the default representation of the given argument using the standard `fmt.Print` function and enforces a linebreak.
categories: [functions]
keywords: []
menu:
docs:
parent: functions
function:
aliases: [println]
returnType: string
signatures: [fmt.Println INPUT]
relatedFunctions:
- fmt.Print
- fmt.Printf
- fmt.Println
aliases: [/functions/println]
---
```go-html-template
{{ println "foo" }} → "foo\n"
```

View File

@@ -0,0 +1,30 @@
---
title: fmt.Warnf
linkTitle: warnf
description: Log a WARNING from a template.
categories: [functions]
keywords: []
menu:
docs:
parent: functions
function:
aliases: [warnf]
returnType: string
signatures: ['fmt.Warnf FORMAT [INPUT]']
relatedFunctions:
- fmt.Errorf
- fmt.Erroridf
- fmt.Warnf
aliases: [/functions/warnf]
---
The documentation for [Go's fmt package] describes the structure and content of the format string.
Like the [`printf`] function, the `warnf` function evaluates the format string. It then prints the result to the WARNING log. Hugo prints each unique message once to avoid flooding the log with duplicate warnings.
```go-html-template
{{ warnf "Copyright notice missing from site configuration" }}
```
[`printf`]: /functions/fmt/printf
[Go's fmt package]: https://pkg.go.dev/fmt