mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-19 21:21:39 +02:00
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:
26
docs/content/en/functions/fmt/Errorf.md
Normal file
26
docs/content/en/functions/fmt/Errorf.md
Normal 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
|
40
docs/content/en/functions/fmt/Erroridf.md
Normal file
40
docs/content/en/functions/fmt/Erroridf.md
Normal 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
|
20
docs/content/en/functions/fmt/Print.md
Normal file
20
docs/content/en/functions/fmt/Print.md
Normal 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]
|
||||
```
|
39
docs/content/en/functions/fmt/Printf.md
Normal file
39
docs/content/en/functions/fmt/Printf.md
Normal 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">
|
||||
```
|
18
docs/content/en/functions/fmt/Println.md
Normal file
18
docs/content/en/functions/fmt/Println.md
Normal 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
|
||||
```
|
33
docs/content/en/functions/fmt/Warnf.md
Normal file
33
docs/content/en/functions/fmt/Warnf.md
Normal 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
|
13
docs/content/en/functions/fmt/_common/_index.md
Normal file
13
docs/content/en/functions/fmt/_common/_index.md
Normal 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.
|
||||
-->
|
7
docs/content/en/functions/fmt/_common/fmt-layout.md
Normal file
7
docs/content/en/functions/fmt/_common/fmt-layout.md
Normal 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
|
12
docs/content/en/functions/fmt/_index.md
Normal file
12
docs/content/en/functions/fmt/_index.md
Normal 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.
|
Reference in New Issue
Block a user