Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'

```
git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash
```

Closes #11925
This commit is contained in:
Bjørn Erik Pedersen
2024-01-27 10:48:33 +01:00
1158 changed files with 64103 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
---
title: fmt.Errorf
description: Log an ERROR from a template.
categories: []
keywords: []
action:
aliases: [errorf]
related:
- functions/fmt/Erroridf
- functions/fmt/Warnf
returnType: string
signatures: ['fmt.Errorf FORMAT [INPUT]']
aliases: [/functions/errorf]
---
{{% include "functions/fmt/_common/fmt-layout.md" %}}
The `errorf` function evaluates the format string, then prints the result to the ERROR log and fails the build.
```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

View File

@@ -0,0 +1,40 @@
---
title: fmt.Erroridf
description: Log a suppressable ERROR from a template.
categories: []
keywords: []
action:
aliases: [erroridf]
related:
- functions/fmt/Errorf
- functions/fmt/Warnf
returnType: string
signatures: ['fmt.Erroridf ID FORMAT [INPUT]']
aliases: [/functions/erroridf]
---
{{% include "functions/fmt/_common/fmt-layout.md" %}}
The `erroridf` function evaluates the format string, then prints the result to the ERROR log and fails the build. 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.
You can suppress this error by adding the following to your site configuration:
ignoreErrors = ['error-42']
```
To suppress this message:
{{< code-toggle file=hugo >}}
ignoreErrors = ["error-42"]
{{< /code-toggle >}}
[`errorf`]: /functions/fmt/errorf

View File

@@ -0,0 +1,20 @@
---
title: fmt.Print
description: Prints the default representation of the given arguments using the standard `fmt.Print` function.
categories: []
keywords: []
action:
aliases: [print]
related:
- functions/fmt/Printf
- functions/fmt/Println
returnType: string
signatures: [fmt.Print INPUT]
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,39 @@
---
title: fmt.Printf
description: Formats a string using the standard `fmt.Sprintf` function.
categories: []
keywords: []
action:
aliases: [printf]
related:
- functions/fmt/Print
- functions/fmt/Println
returnType: string
signatures: ['fmt.Printf FORMAT [INPUT]']
aliases: [/functions/printf]
---
{{% include "functions/fmt/_common/fmt-layout.md" %}}
```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,18 @@
---
title: fmt.Println
description: Prints the default representation of the given argument using the standard `fmt.Print` function and enforces a line break.
categories: []
keywords: []
action:
aliases: [println]
related:
- functions/fmt/Print
- functions/fmt/Printf
returnType: string
signatures: [fmt.Println INPUT]
aliases: [/functions/println]
---
```go-html-template
{{ println "foo" }} → foo\n
```

View File

@@ -0,0 +1,33 @@
---
title: fmt.Warnf
description: Log a WARNING from a template.
categories: []
keywords: []
action:
aliases: [warnf]
related:
- functions/fmt/Errorf
- functions/fmt/Erroridf
returnType: string
signatures: ['fmt.Warnf FORMAT [INPUT]']
aliases: [/functions/warnf]
---
{{% include "functions/fmt/_common/fmt-layout.md" %}}
The `warnf` function evaluates the format string, 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 "The %q shortcode was unable to find %s. See %s" .Name $file .Position }}
```
To prevent suppression of duplicate messages when using `warnf` for debugging, make each message unique with the [`math.Counter`] function. For example:
```go-html-template
{{ range site.RegularPages }}
{{ .Section | warnf "%#[2]v [%[1]d]" math.Counter }}
{{ end }}
```
[`math.Counter`]: /functions/math/counter

View File

@@ -0,0 +1,13 @@
---
cascade:
_build:
list: never
publishResources: false
render: never
---
<!--
Files within this headless branch bundle are markdown snippets. Each file must contain front matter delimiters, though front matter fields are not required.
Include the rendered content using the "include" shortcode.
-->

View File

@@ -0,0 +1,7 @@
---
# Do not remove front matter.
---
The documentation for Go's [fmt] package describes the structure and content of the format string.
[fmt]: https://pkg.go.dev/fmt

View File

@@ -0,0 +1,12 @@
---
title: Fmt functions
linkTitle: fmt
description: Template functions to print strings within a template or to print messages to the terminal
categories: []
keywords: []
menu:
docs:
parent: functions
---
Use these functions to print strings within a template or to print messages to the terminal.