Update fmt functions

This commit is contained in:
Joe Mooring 2023-11-26 15:37:35 -08:00 committed by GitHub
parent 740f5ef96f
commit 994d4374b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 19 deletions

View File

@ -13,9 +13,9 @@ action:
aliases: [/functions/errorf] aliases: [/functions/errorf]
--- ---
The documentation for [Go's fmt package] describes the structure and content of the format string. {{% include "functions/fmt/_common/fmt-layout.md" %}}
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. The `errorf` function evaluates the format string, then prints the result to the ERROR log and fails the build.
```go-html-template ```go-html-template
{{ errorf "The %q shortcode requires a src parameter. See %s" .Name .Position }} {{ errorf "The %q shortcode requires a src parameter. See %s" .Name .Position }}
@ -24,5 +24,3 @@ Like the [`printf`] function, the `errorf` function evaluates the format string
Use the [`erroridf`] function to allow optional suppression of specific errors. Use the [`erroridf`] function to allow optional suppression of specific errors.
[`erroridf`]: /functions/fmt/erroridf [`erroridf`]: /functions/fmt/erroridf
[`printf`]: /functions/fmt/printf
[Go's fmt package]: https://pkg.go.dev/fmt

View File

@ -13,16 +13,14 @@ action:
aliases: [/functions/erroridf] aliases: [/functions/erroridf]
--- ---
The documentation for [Go's fmt package] describes the structure and content of the format string. {{% include "functions/fmt/_common/fmt-layout.md" %}}
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. 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.
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: This template code:
```go-html-template ```go-html-template
{{ erroridf "error-42" "You should consider fixing this." }} {{ erroridf "The %q shortcode was unable to find %s. See %s" .Name $file .Position }}
``` ```
Produces this console log: Produces this console log:
@ -40,4 +38,3 @@ ignoreErrors = ["error-42"]
{{< /code-toggle >}} {{< /code-toggle >}}
[`errorf`]: /functions/fmt/errorf [`errorf`]: /functions/fmt/errorf
[Go's fmt package]: https://pkg.go.dev/fmt

View File

@ -13,9 +13,7 @@ action:
aliases: [/functions/printf] aliases: [/functions/printf]
--- ---
The documentation for [Go's fmt package] describes the structure and content of the format string. {{% include "functions/fmt/_common/fmt-layout.md" %}}
[Go's fmt package]: https://pkg.go.dev/fmt
```go-html-template ```go-html-template
{{ $var := "world" }} {{ $var := "world" }}

View File

@ -13,13 +13,10 @@ action:
aliases: [/functions/warnf] aliases: [/functions/warnf]
--- ---
The documentation for [Go's fmt package] describes the structure and content of the format string. {{% include "functions/fmt/_common/fmt-layout.md" %}}
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. 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 ```go-html-template
{{ warnf "Copyright notice missing from site configuration" }} {{ warnf "The %q shortcode was unable to find %s. See %s" .Name $file .Position }}
``` ```
[`printf`]: /functions/fmt/printf
[Go's fmt package]: https://pkg.go.dev/fmt

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