mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-28 06:30:33 +03:00
Merge commit '5be51ac3db
'
This commit is contained in:
commit
653f1c1d46
987 changed files with 12379 additions and 14083 deletions
|
@ -1,13 +0,0 @@
|
|||
---
|
||||
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.
|
||||
-->
|
|
@ -1,23 +0,0 @@
|
|||
---
|
||||
_comment: Do not remove front matter.
|
||||
---
|
||||
|
||||
Path|Pattern|Match
|
||||
:--|:--|:--
|
||||
`images/foo/a.jpg`|`images/foo/*.jpg`|`true`
|
||||
`images/foo/a.jpg`|`images/foo/*.*`|`true`
|
||||
`images/foo/a.jpg`|`images/foo/*`|`true`
|
||||
`images/foo/a.jpg`|`images/*/*.jpg`|`true`
|
||||
`images/foo/a.jpg`|`images/*/*.*`|`true`
|
||||
`images/foo/a.jpg`|`images/*/*`|`true`
|
||||
`images/foo/a.jpg`|`*/*/*.jpg`|`true`
|
||||
`images/foo/a.jpg`|`*/*/*.*`|`true`
|
||||
`images/foo/a.jpg`|`*/*/*`|`true`
|
||||
`images/foo/a.jpg`|`**/*.jpg`|`true`
|
||||
`images/foo/a.jpg`|`**/*.*`|`true`
|
||||
`images/foo/a.jpg`|`**/*`|`true`
|
||||
`images/foo/a.jpg`|`**`|`true`
|
||||
`images/foo/a.jpg`|`*/*.jpg`|`false`
|
||||
`images/foo/a.jpg`|`*.jpg`|`false`
|
||||
`images/foo/a.jpg`|`*.*`|`false`
|
||||
`images/foo/a.jpg`|`*`|`false`
|
|
@ -1,14 +0,0 @@
|
|||
---
|
||||
_comment: Do not remove front matter.
|
||||
---
|
||||
|
||||
Hugo uses Go's [text/template] and [html/template] packages.
|
||||
|
||||
The text/template package implements data-driven templates for generating textual output, while the html/template package implements data-driven templates for generating HTML output safe against code injection.
|
||||
|
||||
By default, Hugo uses the html/template package when rendering HTML files.
|
||||
|
||||
To generate HTML output that is safe against code injection, the html/template package escapes strings in certain contexts.
|
||||
|
||||
[text/template]: https://pkg.go.dev/text/template
|
||||
[html/template]: https://pkg.go.dev/html/template
|
|
@ -1,59 +0,0 @@
|
|||
---
|
||||
_comment: Do not remove front matter.
|
||||
---
|
||||
|
||||
anchorLineNos
|
||||
: (`bool`) Whether to render each line number as an HTML anchor element, setting the `id` attribute of the surrounding `span` element to the line number. Irrelevant if `lineNos` is `false`. Default is `false`.
|
||||
|
||||
codeFences
|
||||
: (`bool`) Whether to highlight fenced code blocks. Default is `true`.
|
||||
|
||||
guessSyntax
|
||||
: (`bool`) Whether to automatically detect the language if the `LANG` argument is blank or set to a language for which there is no corresponding [lexer](g). Falls back to a plain text lexer if unable to automatically detect the language. Default is `false`.
|
||||
|
||||
{{% note %}}
|
||||
The Chroma syntax highlighter includes lexers for approximately 250 languages, but only 5 of these have implemented automatic language detection.
|
||||
{{% /note %}}
|
||||
|
||||
hl_Lines
|
||||
: (`string`) A space-delimited list of lines to emphasize within the highlighted code. To emphasize lines 2, 3, 4, and 7, set this value to `2-4 7`. This option is independent of the `lineNoStart` option.
|
||||
|
||||
hl_inline
|
||||
: (`bool`) Whether to render the highlighted code without a wrapping container. Default is `false`.
|
||||
|
||||
lineAnchors
|
||||
: (`string`) When rendering a line number as an HTML anchor element, prepend this value to the `id` attribute of the surrounding `span` element. This provides unique `id` attributes when a page contains two or more code blocks. Irrelevant if `lineNos` or `anchorLineNos` is `false`.
|
||||
|
||||
lineNoStart
|
||||
: (`int`) The number to display at the beginning of the first line. Irrelevant if `lineNos` is `false`. Default is `1`.
|
||||
|
||||
lineNos
|
||||
: (`bool`) Whether to display a number at the beginning of each line. Default is `false`.
|
||||
|
||||
lineNumbersInTable
|
||||
: (`bool`) Whether to render the highlighted code in an HTML table with two cells. The left table cell contains the line numbers, while the right table cell contains the code. Irrelevant if `lineNos` is `false`. Default is `true`.
|
||||
|
||||
noClasses
|
||||
: (`bool`) Whether to use inline CSS styles instead of an external CSS file. To use an external CSS file, set this value to `false` and generate the CSS file using the `hugo gen chromastyles` command. Default is `true`.
|
||||
|
||||
style
|
||||
: (`string`) The CSS styles to apply to the highlighted code. See the [style gallery] for examples. Case-sensitive. Default is `monokai`.
|
||||
|
||||
[style gallery]: https://xyproto.github.io/splash/docs/
|
||||
|
||||
tabWidth
|
||||
: (`int`) Substitute this number of spaces for each tab character in your highlighted code. Irrelevant if `noClasses` is `false`. Default is `4`.
|
||||
|
||||
wrapperClass
|
||||
{{< new-in 0.140.2 />}}
|
||||
: (`string`) The class or classes to use for the outermost element of the highlighted code. Default is `highlight`.
|
||||
|
||||
{{% note %}}
|
||||
Instead of specifying both `lineNos` and `lineNumbersInTable`, you can use the following shorthand notation:
|
||||
|
||||
lineNos=inline
|
||||
: equivalent to `lineNos=true` and `lineNumbersInTable=false`
|
||||
|
||||
lineNos=table
|
||||
: equivalent to `lineNos=true` and `lineNumbersInTable=true`
|
||||
{{% /note %}}
|
|
@ -1,10 +0,0 @@
|
|||
---
|
||||
_comment: Do not remove front matter.
|
||||
---
|
||||
|
||||
{{% note %}}
|
||||
|
||||
Localization of dates, currencies, numbers, and percentages is performed by the [gohugoio/locales] package. The language tag of the current site must match one of the listed locales.
|
||||
|
||||
[gohugoio/locales]: https://github.com/gohugoio/locales
|
||||
{{% /note %}}
|
|
@ -1,12 +0,0 @@
|
|||
---
|
||||
_comment: Do not remove front matter.
|
||||
---
|
||||
|
||||
When specifying the regular expression, use a raw [string literal] (backticks) instead of an interpreted string literal (double quotes) to simplify the syntax. With an interpreted string literal you must escape backslashes.
|
||||
|
||||
Go's regular expression package implements the [RE2 syntax]. The RE2 syntax is a subset of that accepted by [PCRE], roughly speaking, and with various [caveats]. Note that the RE2 `\C` escape sequence is not supported.
|
||||
|
||||
[caveats]: https://swtch.com/~rsc/regexp/regexp3.html#caveats
|
||||
[PCRE]: https://www.pcre.org/
|
||||
[RE2 syntax]: https://github.com/google/re2/wiki/Syntax/
|
||||
[string literal]: https://go.dev/ref/spec#String_literals
|
|
@ -1,46 +0,0 @@
|
|||
---
|
||||
_comment: Do not remove front matter.
|
||||
---
|
||||
|
||||
Format a `time.Time` value based on [Go's reference time]:
|
||||
|
||||
[Go's reference time]: https://pkg.go.dev/time#pkg-constants
|
||||
|
||||
```text
|
||||
Mon Jan 2 15:04:05 MST 2006
|
||||
```
|
||||
|
||||
Create a layout string using these components:
|
||||
|
||||
Description|Valid components
|
||||
:--|:--
|
||||
Year|`"2006" "06"`
|
||||
Month|`"Jan" "January" "01" "1"`
|
||||
Day of the week|`"Mon" "Monday"`
|
||||
Day of the month|`"2" "_2" "02"`
|
||||
Day of the year|`"__2" "002"`
|
||||
Hour|`"15" "3" "03"`
|
||||
Minute|`"4" "04"`
|
||||
Second|`"5" "05"`
|
||||
AM/PM mark|`"PM"`
|
||||
Time zone offsets|`"-0700" "-07:00" "-07" "-070000" "-07:00:00"`
|
||||
|
||||
Replace the sign in the layout string with a Z to print Z instead of an offset for the UTC zone.
|
||||
|
||||
Description|Valid components
|
||||
:--|:--
|
||||
Time zone offsets|`"Z0700" "Z07:00" "Z07" "Z070000" "Z07:00:00"`
|
||||
|
||||
```go-html-template
|
||||
{{ $t := "2023-01-27T23:44:58-08:00" }}
|
||||
{{ $t = time.AsTime $t }}
|
||||
{{ $t = $t.Format "Jan 02, 2006 3:04 PM Z07:00" }}
|
||||
|
||||
{{ $t }} → Jan 27, 2023 11:44 PM -08:00
|
||||
```
|
||||
|
||||
Strings such as `PST` and `CET` are not time zones. They are time zone _abbreviations_.
|
||||
|
||||
Strings such as `-07:00` and `+01:00` are not time zones. They are time zone _offsets_.
|
||||
|
||||
A time zone is a geographic area with the same local time. For example, the time zone abbreviated by `PST` and `PDT` (depending on Daylight Savings Time) is `America/Los_Angeles`.
|
|
@ -1,17 +1,8 @@
|
|||
---
|
||||
title: Functions
|
||||
|
||||
description: Use these functions within your templates and archetypes.
|
||||
categories: []
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
identifier: functions-in-this-section
|
||||
parent: functions
|
||||
weight: 10
|
||||
weight: 10
|
||||
showSectionMenu: true
|
||||
aliases: [/layout/functions/,/templates/functions]
|
||||
---
|
||||
|
||||
Use these functions within your templates and archetypes.
|
||||
|
|
|
@ -3,13 +3,11 @@ title: cast.ToFloat
|
|||
description: Converts a value to a decimal floating-point number (base 10).
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [float]
|
||||
related:
|
||||
- functions/cast/ToInt
|
||||
- functions/cast/ToString
|
||||
returnType: float64
|
||||
signatures: [cast.ToFloat INPUT]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [float]
|
||||
returnType: float64
|
||||
signatures: [cast.ToFloat INPUT]
|
||||
aliases: [/functions/float]
|
||||
---
|
||||
|
||||
|
|
|
@ -2,13 +2,11 @@
|
|||
title: cast.ToInt
|
||||
description: Converts a value to a decimal integer (base 10).
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [int]
|
||||
related:
|
||||
- functions/cast/ToFloat
|
||||
- functions/cast/ToString
|
||||
returnType: int
|
||||
signatures: [cast.ToInt INPUT]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [int]
|
||||
returnType: int
|
||||
signatures: [cast.ToInt INPUT]
|
||||
aliases: [/functions/int]
|
||||
---
|
||||
|
||||
|
@ -46,8 +44,7 @@ With a hexadecimal (base 16) input:
|
|||
{{ int "0x11" }} → 17 (int)
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
Values with a leading zero are octal (base 8). When casting a string representation of a decimal (base 10) number, remove leading zeros:
|
||||
> [!note]
|
||||
> Values with a leading zero are octal (base 8). When casting a string representation of a decimal (base 10) number, remove leading zeros:
|
||||
|
||||
`{{ strings.TrimLeft "0" "0011" | int }} → 11`
|
||||
{{% /note %}}
|
||||
|
|
|
@ -3,13 +3,11 @@ title: cast.ToString
|
|||
description: Converts a value to a string.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [string]
|
||||
related:
|
||||
- functions/cast/ToFloat
|
||||
- functions/cast/ToInt
|
||||
returnType: string
|
||||
signatures: [cast.ToString INPUT]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [string]
|
||||
returnType: string
|
||||
signatures: [cast.ToString INPUT]
|
||||
aliases: [/functions/string]
|
||||
---
|
||||
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
---
|
||||
title: Cast functions
|
||||
linkTitle: cast
|
||||
description: Template functions to cast a value from one data type to another.
|
||||
description: Use these functions to cast a value from one data type to another.
|
||||
categories: []
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
---
|
||||
|
||||
Use these functions to cast a value from one data type to another.
|
||||
|
|
|
@ -3,13 +3,11 @@ title: collections.After
|
|||
description: Slices an array to the items after the Nth item.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [after]
|
||||
related:
|
||||
- functions/collections/First
|
||||
- functions/collections/Last
|
||||
returnType: any
|
||||
signatures: [collections.After INDEX COLLECTION]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [after]
|
||||
returnType: any
|
||||
signatures: [collections.After INDEX COLLECTION]
|
||||
aliases: [/functions/after]
|
||||
---
|
||||
|
||||
|
@ -40,7 +38,7 @@ You can use `after` in combination with the [`first`] function and Hugo's [power
|
|||
1. The top row is titled "Featured" and shows only the most recently published article (i.e. by `publishdate` in the content files' front matter).
|
||||
1. The second row is titled "Recent Articles" and shows only the 2nd- to 4th-most recently published articles.
|
||||
|
||||
{{< code file=layouts/section/articles.html >}}
|
||||
```go-html-template {file="layouts/section/articles.html"}
|
||||
{{ define "main" }}
|
||||
<section class="row featured-article">
|
||||
<h2>Featured Article</h2>
|
||||
|
@ -63,7 +61,7 @@ You can use `after` in combination with the [`first`] function and Hugo's [power
|
|||
{{ end }}
|
||||
</div>
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
[`first`]: /functions/collections/first/
|
||||
[`slice`]: /functions/collections/slice/
|
||||
|
|
|
@ -3,14 +3,13 @@ title: collections.Append
|
|||
description: Appends one or more elements to a slice and returns the resulting slice.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [append]
|
||||
related:
|
||||
- functions/collections/Merge
|
||||
returnType: any
|
||||
signatures:
|
||||
- collections.Append ELEMENT [ELEMENT...] COLLECTION
|
||||
- collections.Append COLLECTION1 COLLECTION2
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [append]
|
||||
returnType: any
|
||||
signatures:
|
||||
- collections.Append ELEMENT [ELEMENT...] COLLECTION
|
||||
- collections.Append COLLECTION1 COLLECTION2
|
||||
aliases: [/functions/append]
|
||||
---
|
||||
|
||||
|
|
|
@ -3,11 +3,11 @@ title: collections.Apply
|
|||
description: Returns a new collection with each element transformed by the given function.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [apply]
|
||||
related: []
|
||||
returnType: '[]any'
|
||||
signatures: [collections.Apply COLLECTION FUNCTION PARAM...]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [apply]
|
||||
returnType: '[]any'
|
||||
signatures: [collections.Apply COLLECTION FUNCTION PARAM...]
|
||||
aliases: [/functions/apply]
|
||||
---
|
||||
|
||||
|
|
|
@ -3,14 +3,11 @@ title: collections.Complement
|
|||
description: Returns the elements of the last collection that are not in any of the others.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [complement]
|
||||
related:
|
||||
- functions/collections/Intersect
|
||||
- functions/collections/SymDiff
|
||||
- functions/collections/Union
|
||||
returnType: any
|
||||
signatures: ['collections.Complement COLLECTION [COLLECTION...]']
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [complement]
|
||||
returnType: any
|
||||
signatures: ['collections.Complement COLLECTION [COLLECTION...]']
|
||||
aliases: [/functions/complement]
|
||||
---
|
||||
|
||||
|
@ -24,11 +21,8 @@ To find the elements within `$c3` that do not exist in `$c1` or `$c2`:
|
|||
{{ complement $c1 $c2 $c3 }} → [1 2]
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
Make your code simpler to understand by using a [chained pipeline]:
|
||||
|
||||
[chained pipeline]: https://pkg.go.dev/text/template#hdr-Pipelines
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> Make your code simpler to understand by using a [chained pipeline]:
|
||||
|
||||
```go-html-template
|
||||
{{ $c3 | complement $c1 $c2 }} → [1 2]
|
||||
|
@ -55,11 +49,8 @@ To list everything except blog articles (`blog`) and frequently asked questions
|
|||
{{ end }}
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
Although the example above demonstrates the `complement` function, you could use the [`where`] function as well:
|
||||
|
||||
[`where`]: /functions/collections/where/
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> Although the example above demonstrates the `complement` function, you could use the [`where`] function as well:
|
||||
|
||||
```go-html-template
|
||||
{{ range where site.RegularPages "Type" "not in" (slice "blog" "faqs") }}
|
||||
|
@ -77,4 +68,6 @@ In this example we use the `complement` function to remove [stop words] from a s
|
|||
{{ delimit $filtered " " }} → The quick brown fox jumps lazy dog
|
||||
```
|
||||
|
||||
[`where`]: /functions/collections/where/
|
||||
[chained pipeline]: https://pkg.go.dev/text/template#hdr-Pipelines
|
||||
[stop words]: https://en.wikipedia.org/wiki/Stop_word
|
||||
|
|
|
@ -3,12 +3,11 @@ title: collections.Delimit
|
|||
description: Loops through any array, slice, or map and returns a string of all the values separated by a delimiter.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [delimit]
|
||||
related:
|
||||
- functions/strings/Split
|
||||
returnType: string
|
||||
signatures: ['collections.Delimit COLLECTION DELIMITER [LAST]']
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [delimit]
|
||||
returnType: string
|
||||
signatures: ['collections.Delimit COLLECTION DELIMITER [LAST]']
|
||||
aliases: [/functions/delimit]
|
||||
---
|
||||
|
||||
|
@ -22,9 +21,8 @@ Delimit a slice:
|
|||
|
||||
Delimit a map:
|
||||
|
||||
{{% note %}}
|
||||
The `delimit` function sorts maps by key, returning the values.
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> The `delimit` function sorts maps by key, returning the values.
|
||||
|
||||
```go-html-template
|
||||
{{ $m := dict "b" 2 "a" 1 "c" 3 }}
|
||||
|
|
|
@ -3,12 +3,11 @@ title: collections.Dictionary
|
|||
description: Returns a map composed of the given key-value pairs.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [dict]
|
||||
related:
|
||||
- functions/collections/Slice
|
||||
returnType: map[string]any
|
||||
signatures: ['collections.Dictionary [VALUE...]']
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [dict]
|
||||
returnType: map[string]any
|
||||
signatures: ['collections.Dictionary [VALUE...]']
|
||||
aliases: [/functions/dict]
|
||||
---
|
||||
|
||||
|
|
|
@ -3,14 +3,11 @@ title: collections.First
|
|||
description: Returns the given collection, limited to the first N elements.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [first]
|
||||
related:
|
||||
- functions/collections/After
|
||||
- functions/collections/Last
|
||||
- methods/pages/Limit
|
||||
returnType: any
|
||||
signatures: [collections.First N COLLECTION]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [first]
|
||||
returnType: any
|
||||
signatures: [collections.First N COLLECTION]
|
||||
aliases: [/functions/first]
|
||||
---
|
||||
|
||||
|
@ -23,7 +20,7 @@ aliases: [/functions/first]
|
|||
Set `N` to zero to return an empty collection.
|
||||
|
||||
```go-html-template
|
||||
{{ $emptyPageCollection := first 0 .Pages}}
|
||||
{{ $emptyPageCollection := first 0 .Pages }}
|
||||
```
|
||||
|
||||
Use `first` and [`where`] together.
|
||||
|
|
|
@ -3,11 +3,11 @@ title: collections.Group
|
|||
description: Groups the given page collection by the given key.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [group]
|
||||
related: []
|
||||
returnType: any
|
||||
signatures: [collections.Group KEY PAGES]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [group]
|
||||
returnType: any
|
||||
signatures: [collections.Group KEY PAGES]
|
||||
aliases: [/functions/group]
|
||||
---
|
||||
|
||||
|
|
|
@ -3,16 +3,11 @@ title: collections.In
|
|||
description: Reports whether the given value is a member of the given set.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [in]
|
||||
related:
|
||||
- functions/strings/Contains
|
||||
- functions/strings/ContainsAny
|
||||
- functions/strings/ContainsNonSpace
|
||||
- functions/strings/HasPrefix
|
||||
- functions/strings/HasSuffix
|
||||
returnType: bool
|
||||
signatures: [collections.In SET VALUE]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [in]
|
||||
returnType: bool
|
||||
signatures: [collections.In SET VALUE]
|
||||
aliases: [/functions/in]
|
||||
---
|
||||
|
||||
|
|
|
@ -3,12 +3,11 @@ title: collections.Index
|
|||
description: Returns the object, element, or value associated with the given key or keys.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [index]
|
||||
related: []
|
||||
returnType: any
|
||||
signatures:
|
||||
- collections.Index COLLECTION KEY...
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [index]
|
||||
returnType: any
|
||||
signatures: [collections.Index COLLECTION KEY...]
|
||||
aliases: [/functions/index,/functions/index-function]
|
||||
---
|
||||
|
||||
|
|
|
@ -3,14 +3,11 @@ title: collections.Intersect
|
|||
description: Returns the common elements of two arrays or slices, in the same order as the first array.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [intersect]
|
||||
related:
|
||||
- functions/collections/Complement
|
||||
- functions/collections/SymDiff
|
||||
- functions/collections/Union
|
||||
returnType: any
|
||||
signatures: [collections.Intersect SET1 SET2]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [intersect]
|
||||
returnType: any
|
||||
signatures: [collections.Intersect SET1 SET2]
|
||||
aliases: [/functions/intersect]
|
||||
---
|
||||
|
||||
|
|
|
@ -3,13 +3,11 @@ title: collections.IsSet
|
|||
description: Reports whether the key exists within the collection.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [isset]
|
||||
related:
|
||||
- functions/go-template/if
|
||||
- functions/go-template/with
|
||||
returnType: bool
|
||||
signatures: [collections.IsSet COLLECTION KEY]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [isset]
|
||||
returnType: bool
|
||||
signatures: [collections.IsSet COLLECTION KEY]
|
||||
aliases: [/functions/isset]
|
||||
---
|
||||
|
||||
|
@ -40,6 +38,5 @@ But if the value of `showHeroImage` is `false`, we can't use either `if` or `wit
|
|||
{{ end }}
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
When using the `isset` function you must reference the key using lower case. See the previous example.
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> When using the `isset` function you must reference the key using lower case. See the previous example.
|
||||
|
|
|
@ -3,12 +3,11 @@ title: collections.KeyVals
|
|||
description: Returns a KeyVals struct.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [keyVals]
|
||||
related:
|
||||
- methods/pages/Related
|
||||
returnType: types.KeyValues
|
||||
signatures: [collections.KeyVals KEY VALUE...]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [keyVals]
|
||||
returnType: types.KeyValues
|
||||
signatures: [collections.KeyVals KEY VALUE...]
|
||||
aliases: [/functions/keyvals]
|
||||
---
|
||||
|
||||
|
@ -16,7 +15,7 @@ The primary application for this function is the definition of the `namedSlices`
|
|||
|
||||
[`Related`]: /methods/pages/related/
|
||||
|
||||
See [related content](/content-management/related).
|
||||
See [related content](/content-management/related-content/).
|
||||
|
||||
```go-html-template
|
||||
{{ $kv := keyVals "foo" "a" "b" "c" }}
|
||||
|
|
|
@ -3,13 +3,11 @@ title: collections.Last
|
|||
description: Returns the given collection, limited to the last N elements.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [last]
|
||||
related:
|
||||
- functions/collections/After
|
||||
- functions/collections/First
|
||||
returnType: any
|
||||
signatures: [collections.Last N COLLECTION]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [last]
|
||||
returnType: any
|
||||
signatures: [collections.Last N COLLECTION]
|
||||
aliases: [/functions/last]
|
||||
---
|
||||
|
||||
|
@ -22,7 +20,7 @@ aliases: [/functions/last]
|
|||
Set `N` to zero to return an empty collection.
|
||||
|
||||
```go-html-template
|
||||
{{ $emptyPageCollection := last 0 .Pages}}
|
||||
{{ $emptyPageCollection := last 0 .Pages }}
|
||||
```
|
||||
|
||||
Use `last` and [`where`] together.
|
||||
|
|
|
@ -3,12 +3,11 @@ title: collections.Merge
|
|||
description: Returns the result of merging two or more maps.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [merge]
|
||||
related:
|
||||
- functions/collections/Append
|
||||
returnType: any
|
||||
signatures: [collections.Merge MAP MAP...]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [merge]
|
||||
returnType: any
|
||||
signatures: [collections.Merge MAP MAP...]
|
||||
aliases: [/functions/merge]
|
||||
---
|
||||
|
||||
|
@ -64,6 +63,5 @@ Example 4
|
|||
{{ $merged.z.a }} → huey
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
Regardless of depth, merging only applies to maps. For slices, use [append](/functions/collections/append).
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> Regardless of depth, merging only applies to maps. For slices, use [append](/functions/collections/append).
|
||||
|
|
|
@ -3,23 +3,18 @@ title: collections.NewScratch
|
|||
description: Returns a locally scoped "scratch pad" to store and manipulate data.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [newScratch]
|
||||
related:
|
||||
- methods/page/Store
|
||||
- methods/site/Store
|
||||
- methods/shortcode/Store
|
||||
- functions/hugo/Store
|
||||
returnType: maps.Scratch
|
||||
signatures: [collections.NewScratch ]
|
||||
toc: true
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [newScratch]
|
||||
returnType: maps.Scratch
|
||||
signatures: [collections.NewScratch ]
|
||||
---
|
||||
|
||||
Use the `collections.NewScratch` function to create a locally scoped [scratch pad](g) to store and manipulate data. To create a scratch pad with a different [scope](g), refer to the [scope](#scope) section below.
|
||||
|
||||
## Methods
|
||||
|
||||
###### Set
|
||||
### Set
|
||||
|
||||
Sets the value of the given key.
|
||||
|
||||
|
@ -28,7 +23,7 @@ Sets the value of the given key.
|
|||
{{ $s.Set "greeting" "Hello" }}
|
||||
```
|
||||
|
||||
###### Get
|
||||
### Get
|
||||
|
||||
Gets the value of the given key.
|
||||
|
||||
|
@ -38,7 +33,7 @@ Gets the value of the given key.
|
|||
{{ $s.Get "greeting" }} → Hello
|
||||
```
|
||||
|
||||
###### Add
|
||||
### Add
|
||||
|
||||
Adds the given value to existing value(s) of the given key.
|
||||
|
||||
|
@ -65,7 +60,7 @@ For single values, `Add` accepts values that support Go's `+` operator. If the f
|
|||
{{ $s.Get "greetings" }} → [Hello Welcome Cheers]
|
||||
```
|
||||
|
||||
###### SetInMap
|
||||
### SetInMap
|
||||
|
||||
Takes a `key`, `mapKey` and `value` and adds a map of `mapKey` and `value` to the given `key`.
|
||||
|
||||
|
@ -76,7 +71,7 @@ Takes a `key`, `mapKey` and `value` and adds a map of `mapKey` and `value` to th
|
|||
{{ $s.Get "greetings" }} → map[english:Hello french:Bonjour]
|
||||
```
|
||||
|
||||
###### DeleteInMap
|
||||
### DeleteInMap
|
||||
|
||||
Takes a `key` and `mapKey` and removes the map of `mapKey` from the given `key`.
|
||||
|
||||
|
@ -88,7 +83,7 @@ Takes a `key` and `mapKey` and removes the map of `mapKey` from the given `key`.
|
|||
{{ $s.Get "greetings" }} → map[french:Bonjour]
|
||||
```
|
||||
|
||||
###### GetSortedMapValues
|
||||
### GetSortedMapValues
|
||||
|
||||
Returns an array of values from `key` sorted by `mapKey`.
|
||||
|
||||
|
@ -99,7 +94,7 @@ Returns an array of values from `key` sorted by `mapKey`.
|
|||
{{ $s.GetSortedMapValues "greetings" }} → [Hello Bonjour]
|
||||
```
|
||||
|
||||
###### Delete
|
||||
### Delete
|
||||
|
||||
Removes the given key.
|
||||
|
||||
|
@ -109,9 +104,9 @@ Removes the given key.
|
|||
{{ $s.Delete "greeting" }}
|
||||
```
|
||||
|
||||
###### Values
|
||||
### Values
|
||||
|
||||
Returns the raw backing map. Do not use with `Scratch` or `Store` methods on a `Page` object due to concurrency issues.
|
||||
Returns the raw backing map. Do not use with `Store` methods on a `Page` object due to concurrency issues.
|
||||
|
||||
```go-html-template
|
||||
{{ $s := newScratch }}
|
||||
|
|
|
@ -3,13 +3,11 @@ title: collections.Querify
|
|||
description: Returns a URL query string composed of the given key-value pairs, encoded and sorted by key.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [querify]
|
||||
related:
|
||||
- functions/go-template/urlquery.md
|
||||
returnType: string
|
||||
signatures:
|
||||
- collections.Querify [VALUE...]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [querify]
|
||||
returnType: string
|
||||
signatures: ['collections.Querify [VALUE...]']
|
||||
aliases: [/functions/querify]
|
||||
---
|
||||
|
||||
|
|
|
@ -3,14 +3,11 @@ title: collections.Reverse
|
|||
description: Reverses the order of a collection.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/collections/Sort
|
||||
- functions/collections/Shuffle
|
||||
- functions/collections/Uniq
|
||||
returnType: any
|
||||
signatures: [collections.Reverse COLLECTION]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: []
|
||||
returnType: any
|
||||
signatures: [collections.Reverse COLLECTION]
|
||||
aliases: [/functions/collections.reverse]
|
||||
---
|
||||
|
||||
|
|
|
@ -3,14 +3,14 @@ title: collections.Seq
|
|||
description: Returns a slice of integers.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [seq]
|
||||
related: []
|
||||
returnType: '[]int'
|
||||
signatures:
|
||||
- collections.Seq LAST
|
||||
- collections.Seq FIRST LAST
|
||||
- collections.Seq FIRST INCREMENT LAST
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [seq]
|
||||
returnType: '[]int'
|
||||
signatures:
|
||||
- collections.Seq LAST
|
||||
- collections.Seq FIRST LAST
|
||||
- collections.Seq FIRST INCREMENT LAST
|
||||
aliases: [/functions/seq]
|
||||
---
|
||||
|
||||
|
@ -31,6 +31,5 @@ A contrived example of iterating over a sequence of integers:
|
|||
{{ $product }} → 24
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
The slice created by the `seq` function is limited to 2000 elements.
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> The slice created by the `seq` function is limited to 2000 elements.
|
||||
|
|
|
@ -3,14 +3,11 @@ title: collections.Shuffle
|
|||
description: Returns a random permutation of a given array or slice.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [shuffle]
|
||||
related:
|
||||
- functions/collections/Reverse
|
||||
- functions/collections/Sort
|
||||
- functions/collections/Uniq
|
||||
returnType: any
|
||||
signatures: [collections.Shuffle COLLECTION]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [shuffle]
|
||||
returnType: any
|
||||
signatures: [collections.Shuffle COLLECTION]
|
||||
aliases: [/functions/shuffle]
|
||||
---
|
||||
|
||||
|
|
|
@ -3,12 +3,11 @@ title: collections.Slice
|
|||
description: Returns a slice composed of the given values.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [slice]
|
||||
related:
|
||||
- functions/collections/Dictionary
|
||||
returnType: any
|
||||
signatures: ['collections.Slice [VALUE...]']
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [slice]
|
||||
returnType: any
|
||||
signatures: ['collections.Slice [VALUE...]']
|
||||
aliases: [/functions/slice]
|
||||
---
|
||||
|
||||
|
|
|
@ -3,15 +3,11 @@ title: collections.Sort
|
|||
description: Sorts slices, maps, and page collections.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [sort]
|
||||
related:
|
||||
- functions/collections/Reverse
|
||||
- functions/collections/Shuffle
|
||||
- functions/collections/Uniq
|
||||
returnType: any
|
||||
signatures: ['collections.Sort COLLECTION [KEY] [ORDER]']
|
||||
toc: true
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [sort]
|
||||
returnType: any
|
||||
signatures: ['collections.Sort COLLECTION [KEY] [ORDER]']
|
||||
aliases: [/functions/sort]
|
||||
---
|
||||
|
||||
|
@ -65,9 +61,8 @@ firstName = "Jean"
|
|||
lastName = "Valjean"
|
||||
{{< /code-toggle >}}
|
||||
|
||||
{{% note %}}
|
||||
When sorting maps, the `KEY` argument must be lowercase.
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> When sorting maps, the `KEY` argument must be lowercase.
|
||||
|
||||
### Ascending order {#map-ascending-order}
|
||||
|
||||
|
@ -141,11 +136,8 @@ After sorting:
|
|||
|
||||
## Sort a page collection
|
||||
|
||||
{{% note %}}
|
||||
Although you can use the `sort` function to sort a page collection, Hugo provides [sorting and grouping methods] as well.
|
||||
|
||||
[sorting and grouping methods]: /methods/pages/
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> Although you can use the `sort` function to sort a page collection, Hugo provides [sorting and grouping methods] as well.
|
||||
|
||||
In this contrived example, sort the site's regular pages by `.Type` in descending order:
|
||||
|
||||
|
@ -154,3 +146,5 @@ In this contrived example, sort the site's regular pages by `.Type` in descendin
|
|||
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
[sorting and grouping methods]: /methods/pages/
|
||||
|
|
|
@ -3,15 +3,11 @@ title: collections.SymDiff
|
|||
description: Returns the symmetric difference of two collections.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [symdiff]
|
||||
related:
|
||||
- functions/collections/Complement
|
||||
- functions/collections/Intersect
|
||||
- functions/collections/SymDiff
|
||||
- functions/collections/Union
|
||||
returnType: any
|
||||
signatures: [COLLECTION | collections.SymDiff COLLECTION]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [symdiff]
|
||||
returnType: any
|
||||
signatures: [COLLECTION | collections.SymDiff COLLECTION]
|
||||
aliases: [/functions/symdiff]
|
||||
---
|
||||
|
||||
|
|
|
@ -3,32 +3,24 @@ title: collections.Union
|
|||
description: Given two arrays or slices, returns a new array that contains the elements that belong to either or both arrays/slices.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [union]
|
||||
related:
|
||||
- functions/collections/Complement
|
||||
- functions/collections/Intersect
|
||||
- functions/collections/SymDiff
|
||||
- functions/collections/Union
|
||||
returnType: any
|
||||
signatures: [collections.Union SET1 SET2]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [union]
|
||||
returnType: any
|
||||
signatures: [collections.Union SET1 SET2]
|
||||
aliases: [/functions/union]
|
||||
---
|
||||
|
||||
Given two arrays (or slices) A and B, this function will return a new array that contains the elements or objects that belong to either A or to B or to both.
|
||||
|
||||
```go-html-template
|
||||
{{ union (slice 1 2 3) (slice 3 4 5) }}
|
||||
<!-- returns [1 2 3 4 5] -->
|
||||
{{ union (slice 1 2 3) (slice 3 4 5) }} → [1 2 3 4 5]
|
||||
|
||||
{{ union (slice 1 2 3) nil }}
|
||||
<!-- returns [1 2 3] -->
|
||||
{{ union (slice 1 2 3) nil }} → [1 2 3]
|
||||
|
||||
{{ union nil (slice 1 2 3) }}
|
||||
<!-- returns [1 2 3] -->
|
||||
{{ union nil (slice 1 2 3) }} → [1 2 3]
|
||||
|
||||
{{ union nil nil }}
|
||||
<!-- returns an error because both arrays/slices have to be of the same type -->
|
||||
{{ union nil nil }} → []
|
||||
```
|
||||
|
||||
## OR filter in where query
|
||||
|
|
|
@ -3,15 +3,11 @@ title: collections.Uniq
|
|||
description: Returns the given collection, removing duplicate elements.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [uniq]
|
||||
related:
|
||||
- functions/collections/Reverse
|
||||
- functions/collections/Shuffle
|
||||
- functions/collections/Sort
|
||||
- functions/collections/Uniq
|
||||
returnType: any
|
||||
signatures: [collections.Uniq COLLECTION]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [uniq]
|
||||
returnType: any
|
||||
signatures: [collections.Uniq COLLECTION]
|
||||
aliases: [/functions/uniq]
|
||||
---
|
||||
|
||||
|
|
|
@ -3,12 +3,11 @@ title: collections.Where
|
|||
description: Returns the given collection, removing elements that do not satisfy the comparison condition.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [where]
|
||||
related: []
|
||||
returnType: any
|
||||
signatures: ['collections.Where COLLECTION KEY [OPERATOR] VALUE']
|
||||
toc: true
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [where]
|
||||
returnType: any
|
||||
signatures: ['collections.Where COLLECTION KEY [OPERATOR] VALUE']
|
||||
aliases: [/functions/where]
|
||||
---
|
||||
|
||||
|
@ -87,12 +86,12 @@ Use any of the following logical operators:
|
|||
`intersect`
|
||||
: (`bool`) Reports whether the given field value (a slice) contains one or more elements in common with `VALUE`. See [details](/functions/collections/intersect).
|
||||
|
||||
`like` {{< new-in 0.116.0 />}}
|
||||
: (`bool`) Reports whether the given field value matches the regular expression specified in `VALUE`. Use the `like` operator to compare `string` values. The `like` operator returns `false` when comparing other data types to the regular expression.
|
||||
`like`
|
||||
: {{< new-in 0.116.0 />}}
|
||||
: (`bool`) Reports whether the given field value matches the [regular expression](g) specified in `VALUE`. Use the `like` operator to compare `string` values. The `like` operator returns `false` when comparing other data types to the regular expression.
|
||||
|
||||
{{% note %}}
|
||||
The examples below perform comparisons within a page collection, but the same comparisons are applicable to a slice of maps.
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> The examples below perform comparisons within a page collection, but the same comparisons are applicable to a slice of maps.
|
||||
|
||||
## String comparison
|
||||
|
||||
|
@ -155,7 +154,7 @@ To return a collection of pages where the "color" page parameter is neither "red
|
|||
|
||||
## Intersection comparison
|
||||
|
||||
Compare a [`slice`] to a [`slice`], returning collection elements with common values. This is frequently used when comparing taxonomy terms.
|
||||
Compare a `slice` to a `slice`, returning collection elements with common values. This is frequently used when comparing taxonomy terms.
|
||||
|
||||
For example, to return a collection of pages where any of the terms in the "genres" taxonomy are "suspense" or "romance":
|
||||
|
||||
|
@ -176,11 +175,10 @@ To return a collection of pages where the "author" page parameter begins with ei
|
|||
{{ $pages := where .Site.RegularPages "Params.author" "like" `(?i)^victor` }}
|
||||
```
|
||||
|
||||
{{% include "functions/_common/regular-expressions.md" %}}
|
||||
{{% include "/_common/functions/regular-expressions.md" %}}
|
||||
|
||||
{{% note %}}
|
||||
Use the `like` operator to compare string values. Comparing other data types will result in an empty collection.
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> Use the `like` operator to compare string values. Comparing other data types will result in an empty collection.
|
||||
|
||||
## Date comparison
|
||||
|
||||
|
@ -188,12 +186,6 @@ Use the `like` operator to compare string values. Comparing other data types wil
|
|||
|
||||
There are four predefined front matter dates: [`date`], [`publishDate`], [`lastmod`], and [`expiryDate`]. Regardless of the front matter data format (TOML, YAML, or JSON) these are [`time.Time`] values, allowing precise comparisons.
|
||||
|
||||
[`date`]: /methods/page/date/
|
||||
[`publishdate`]: /methods/page/publishdate/
|
||||
[`lastmod`]: /methods/page/lastmod/
|
||||
[`expirydate`]: /methods/page/expirydate/
|
||||
[`time.Time`]: https://pkg.go.dev/time#Time
|
||||
|
||||
For example, to return a collection of pages that were created before the current year:
|
||||
|
||||
```go-html-template
|
||||
|
@ -205,20 +197,19 @@ For example, to return a collection of pages that were created before the curren
|
|||
|
||||
With custom front matter dates, the comparison depends on the front matter data format (TOML, YAML, or JSON).
|
||||
|
||||
{{% note %}}
|
||||
Using TOML for pages with custom front matter dates enables precise date comparisons.
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> Using TOML for pages with custom front matter dates enables precise date comparisons.
|
||||
|
||||
With TOML, date values are first-class citizens. TOML has a date data type while JSON and YAML do not. If you quote a TOML date, it is a string. If you do not quote a TOML date value, it is [`time.Time`] value, enabling precise comparisons.
|
||||
|
||||
In the TOML example below, note that the event date is not quoted.
|
||||
|
||||
{{< code file="content/events/2024-user-conference.md" >}}
|
||||
```text {file="content/events/2024-user-conference.md"}
|
||||
+++
|
||||
title = '2024 User Conference"
|
||||
eventDate = 2024-04-01
|
||||
+++
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
To return a collection of future events:
|
||||
|
||||
|
@ -272,8 +263,6 @@ These are equivalent:
|
|||
|
||||
Useful for theme authors, avoid hardcoding section names by using the `where` function with the [`MainSections`] method on a `Site` object.
|
||||
|
||||
[`MainSections`]: /methods/site/mainsections/
|
||||
|
||||
```go-html-template
|
||||
{{ $pages := where .Site.RegularPages "Section" "in" .Site.MainSections }}
|
||||
```
|
||||
|
@ -281,11 +270,10 @@ Useful for theme authors, avoid hardcoding section names by using the `where` fu
|
|||
With this construct, a theme author can instruct users to specify their main sections in the site configuration:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[params]
|
||||
mainSections = ['blog','galleries']
|
||||
{{< /code-toggle >}}
|
||||
|
||||
If `params.mainSections` is not defined in the site configuration, the `MainSections` method returns a slice with one element---the top level section with the most pages.
|
||||
If `mainSections` is not defined in the site configuration, the `MainSections` method returns a slice with one element---the top-level section with the most pages.
|
||||
|
||||
## Boolean/undefined comparison
|
||||
|
||||
|
@ -387,13 +375,11 @@ To exclude a page with an undefined field from a boolean _inequality_ test:
|
|||
1. Create a collection using a nil comparison
|
||||
1. Subtract the second collection from the first collection using the [`collections.Complement`] function.
|
||||
|
||||
[`collections.Complement`]: /functions/collections/complement/
|
||||
|
||||
This template:
|
||||
|
||||
```go-html-template
|
||||
{{ $p1 := where .Site.RegularPages "Params.exclude" "ne" true }}
|
||||
{{ $p2 := where .Site.RegularPages "Params.exclude" "eq" nil }}
|
||||
{{ $p2 := where .Site.RegularPages "Params.exclude" "eq" nil }}
|
||||
<ul>
|
||||
{{ range $p1 | complement $p2 }}
|
||||
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
|
||||
|
@ -413,7 +399,7 @@ This template:
|
|||
|
||||
```go-html-template
|
||||
{{ $p1 := where .Site.RegularPages "Params.exclude" "ne" false }}
|
||||
{{ $p2 := where .Site.RegularPages "Params.exclude" "eq" nil }}
|
||||
{{ $p2 := where .Site.RegularPages "Params.exclude" "eq" nil }}
|
||||
<ul>
|
||||
{{ range $p1 | complement $p2 }}
|
||||
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
|
||||
|
@ -428,3 +414,9 @@ Is rendered to:
|
|||
<li><a href="/posts/post-1/">Post 2</a></li>
|
||||
</ul>
|
||||
```
|
||||
|
||||
[`collections.Complement`]: /functions/collections/complement/
|
||||
[`date`]: /methods/page/date/
|
||||
[`lastmod`]: /methods/page/lastmod/
|
||||
[`MainSections`]: /methods/site/mainsections/
|
||||
[`time.Time`]: https://pkg.go.dev/time#Time
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
---
|
||||
title: Collections functions
|
||||
linkTitle: collections
|
||||
description: Template functions to work with arrays, slices, maps, and page collections.
|
||||
description: Use these functions to work with arrays, slices, maps, and page collections.
|
||||
categories: []
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
---
|
||||
|
||||
Use these functions to work with arrays, slices, maps, and page collections.
|
||||
|
|
|
@ -3,12 +3,11 @@ title: compare.Conditional
|
|||
description: Returns one of two arguments depending on the value of the control argument.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [cond]
|
||||
related:
|
||||
- functions/compare/Default
|
||||
returnType: any
|
||||
signatures: [compare.Conditional CONTROL ARG1 ARG2]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [cond]
|
||||
returnType: any
|
||||
signatures: [compare.Conditional CONTROL ARG1 ARG2]
|
||||
aliases: [/functions/cond]
|
||||
---
|
||||
|
||||
|
|
|
@ -2,27 +2,24 @@
|
|||
title: compare.Default
|
||||
description: Returns the second argument if set, else the first argument.
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [default]
|
||||
related:
|
||||
- functions/compare/Conditional
|
||||
- functions/go-template/Or
|
||||
returnType: any
|
||||
signatures: [compare.Default DEFAULT INPUT]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [default]
|
||||
returnType: any
|
||||
signatures: [compare.Default DEFAULT INPUT]
|
||||
aliases: [/functions/default]
|
||||
---
|
||||
|
||||
The `default` function returns the second argument if set, else the first argument.
|
||||
|
||||
{{% note %}}
|
||||
When the second argument is the boolean `false` value, the `default` function returns `false`. All _other_ falsy values are considered unset.
|
||||
|
||||
{{% include "functions/go-template/_common/truthy-falsy.md" %}}
|
||||
|
||||
To set a default value based on truthiness, use the [`or`] operator instead.
|
||||
|
||||
[`or`]: /functions/go-template/or/
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> When the second argument is the boolean `false` value, the `default` function returns `false`. All _other_ falsy values are considered unset.
|
||||
>
|
||||
> The falsy values are `false`, `0`, any `nil` pointer or interface value, any array, slice, map, or string of length zero, and zero `time.Time` values.
|
||||
>
|
||||
> Everything else is truthy.
|
||||
>
|
||||
> To set a default value based on truthiness, use the [`or`] operator instead.
|
||||
|
||||
The `default` function returns the second argument if set:
|
||||
|
||||
|
@ -46,3 +43,5 @@ The `default` function returns the first argument if the second argument is not
|
|||
{{ default 42 slice }} → 42
|
||||
{{ default 42 <nil> }} → 42
|
||||
```
|
||||
|
||||
[`or`]: /functions/go-template/or/
|
||||
|
|
|
@ -3,16 +3,11 @@ title: compare.Eq
|
|||
description: Returns the boolean truth of arg1 == arg2 || arg1 == arg3.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [eq]
|
||||
related:
|
||||
- functions/compare/Ge
|
||||
- functions/compare/Gt
|
||||
- functions/compare/Le
|
||||
- functions/compare/Lt
|
||||
- functions/compare/Ne
|
||||
returnType: bool
|
||||
signatures: ['compare.Eq ARG1 ARG2 [ARG...]']
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [eq]
|
||||
returnType: bool
|
||||
signatures: ['compare.Eq ARG1 ARG2 [ARG...]']
|
||||
aliases: [/functions/eq]
|
||||
---
|
||||
|
||||
|
|
|
@ -3,16 +3,11 @@ title: compare.Ge
|
|||
description: Returns the boolean truth of arg1 >= arg2 && arg1 >= arg3.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [ge]
|
||||
related:
|
||||
- functions/compare/Eq
|
||||
- functions/compare/Gt
|
||||
- functions/compare/Le
|
||||
- functions/compare/Lt
|
||||
- functions/compare/Ne
|
||||
returnType: bool
|
||||
signatures: ['compare.Ge ARG1 ARG2 [ARG...]']
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [ge]
|
||||
returnType: bool
|
||||
signatures: ['compare.Ge ARG1 ARG2 [ARG...]']
|
||||
aliases: [/functions/ge]
|
||||
---
|
||||
|
||||
|
|
|
@ -3,16 +3,11 @@ title: compare.Gt
|
|||
description: Returns the boolean truth of arg1 > arg2 && arg1 > arg3.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [gt]
|
||||
related:
|
||||
- functions/compare/Eq
|
||||
- functions/compare/Ge
|
||||
- functions/compare/Le
|
||||
- functions/compare/Lt
|
||||
- functions/compare/Ne
|
||||
returnType: bool
|
||||
signatures: ['compare.Gt ARG1 ARG2 [ARG...]']
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [gt]
|
||||
returnType: bool
|
||||
signatures: ['compare.Gt ARG1 ARG2 [ARG...]']
|
||||
aliases: [/functions/gt]
|
||||
---
|
||||
|
||||
|
|
|
@ -3,16 +3,11 @@ title: compare.Le
|
|||
description: Returns the boolean truth of arg1 <= arg2 && arg1 <= arg3.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [le]
|
||||
related:
|
||||
- functions/compare/Eq
|
||||
- functions/compare/Ge
|
||||
- functions/compare/Gt
|
||||
- functions/compare/Lt
|
||||
- functions/compare/Ne
|
||||
returnType: bool
|
||||
signatures: ['compare.Le ARG1 ARG2 [ARG...]']
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [le]
|
||||
returnType: bool
|
||||
signatures: ['compare.Le ARG1 ARG2 [ARG...]']
|
||||
aliases: [/functions/le]
|
||||
---
|
||||
|
||||
|
|
|
@ -3,16 +3,11 @@ title: compare.Lt
|
|||
description: Returns the boolean truth of arg1 < arg2 && arg1 < arg3.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [lt]
|
||||
related:
|
||||
- functions/compare/Eq
|
||||
- functions/compare/Ge
|
||||
- functions/compare/Gt
|
||||
- functions/compare/Le
|
||||
- functions/compare/Ne
|
||||
returnType: bool
|
||||
signatures: ['compare.Lt ARG1 ARG2 [ARG...]']
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [lt]
|
||||
returnType: bool
|
||||
signatures: ['compare.Lt ARG1 ARG2 [ARG...]']
|
||||
aliases: [/functions/lt]
|
||||
---
|
||||
|
||||
|
|
|
@ -3,16 +3,11 @@ title: compare.Ne
|
|||
description: Returns the boolean truth of arg1 != arg2 && arg1 != arg3.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [ne]
|
||||
related:
|
||||
- functions/compare/Eq
|
||||
- functions/compare/Ge
|
||||
- functions/compare/Gt
|
||||
- functions/compare/Le
|
||||
- functions/compare/Lt
|
||||
returnType: bool
|
||||
signatures: ['compare.Ne ARG1 ARG2 [ARG...]']
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [ne]
|
||||
returnType: bool
|
||||
signatures: ['compare.Ne ARG1 ARG2 [ARG...]']
|
||||
aliases: [/functions/ne]
|
||||
---
|
||||
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
---
|
||||
title: Compare functions
|
||||
linkTitle: compare
|
||||
description: Template functions to compare two or more values.
|
||||
description: Use these functions to compare two or more values.
|
||||
categories: []
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
---
|
||||
|
||||
Use these functions to compare two or more values.
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
---
|
||||
title: crypto.FNV32a
|
||||
description: Returns the 32-bit FNV (Fowler–Noll–Vo) non-cryptographic hash of the given string.
|
||||
description: Returns the 32-bit FNV (Fowler-Noll-Vo) non-cryptographic hash of the given string.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related: []
|
||||
returnType: int
|
||||
signatures: [crypto.FNV32a STRING]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: []
|
||||
returnType: int
|
||||
signatures: [crypto.FNV32a STRING]
|
||||
expiryDate: 2026-07-31 # deprecated 2024-07-31 in v0.129.0
|
||||
---
|
||||
|
||||
{{% deprecated-in 0.129.0 %}}
|
||||
{{< deprecated-in 0.129.0 >}}
|
||||
Use [`hash.FNV32a`] instead.
|
||||
|
||||
[`hash.FNV32a`]: /functions/hash/FNV32a/
|
||||
{{% /deprecated-in %}}
|
||||
{{< /deprecated-in >}}
|
||||
|
|
|
@ -3,15 +3,11 @@ title: crypto.HMAC
|
|||
description: Returns a cryptographic hash that uses a key to sign a message.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [hmac]
|
||||
related:
|
||||
- functions/crypto/FNV32a
|
||||
- functions/crypto/MD5
|
||||
- functions/crypto/SHA1
|
||||
- functions/crypto/SHA256
|
||||
returnType: string
|
||||
signatures: ['crypto.HMAC HASH_TYPE KEY MESSAGE [ENCODING]']
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [hmac]
|
||||
returnType: string
|
||||
signatures: ['crypto.HMAC HASH_TYPE KEY MESSAGE [ENCODING]']
|
||||
aliases: [/functions/hmac]
|
||||
---
|
||||
|
||||
|
|
|
@ -3,15 +3,11 @@ title: crypto.MD5
|
|||
description: Hashes the given input and returns its MD5 checksum encoded to a hexadecimal string.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [md5]
|
||||
related:
|
||||
- functions/crypto/FNV32a
|
||||
- functions/crypto/HMAC
|
||||
- functions/crypto/SHA1
|
||||
- functions/crypto/SHA256
|
||||
returnType: string
|
||||
signatures: [crypto.MD5 INPUT]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [md5]
|
||||
returnType: string
|
||||
signatures: [crypto.MD5 INPUT]
|
||||
aliases: [/functions/md5]
|
||||
---
|
||||
|
||||
|
|
|
@ -3,15 +3,11 @@ title: crypto.SHA1
|
|||
description: Hashes the given input and returns its SHA1 checksum encoded to a hexadecimal string.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [sha1]
|
||||
related:
|
||||
- functions/crypto/FNV32a
|
||||
- functions/crypto/HMAC
|
||||
- functions/crypto/MD5
|
||||
- functions/crypto/SHA256
|
||||
returnType: string
|
||||
signatures: [crypto.SHA1 INPUT]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [sha1]
|
||||
returnType: string
|
||||
signatures: [crypto.SHA1 INPUT]
|
||||
aliases: [/functions/sha,/functions/sha1]
|
||||
---
|
||||
|
||||
|
|
|
@ -3,15 +3,11 @@ title: crypto.SHA256
|
|||
description: Hashes the given input and returns its SHA256 checksum encoded to a hexadecimal string.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [sha256]
|
||||
related:
|
||||
- functions/crypto/FNV32a
|
||||
- functions/crypto/HMAC
|
||||
- functions/crypto/MD5
|
||||
- functions/crypto/SHA1
|
||||
returnType: string
|
||||
signatures: [crypto.SHA256 INPUT]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [sha256]
|
||||
returnType: string
|
||||
signatures: [crypto.SHA256 INPUT]
|
||||
aliases: [/functions/sha256]
|
||||
---
|
||||
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
---
|
||||
title: Crypto functions
|
||||
linkTitle: crypto
|
||||
description: Template functions to create cryptographic hashes.
|
||||
description: Use these functions to create cryptographic hashes.
|
||||
categories: []
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
---
|
||||
|
||||
Use these functions to create cryptographic hashes.
|
||||
|
|
|
@ -3,14 +3,11 @@ title: css.PostCSS
|
|||
description: Processes the given resource with PostCSS using any PostCSS plugin.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [postCSS]
|
||||
related:
|
||||
- functions/css/Sass
|
||||
- functions/css/TailwindCSS
|
||||
returnType: resource.Resource
|
||||
signatures: ['css.PostCSS [OPTIONS] RESOURCE']
|
||||
toc: true
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [postCSS]
|
||||
returnType: resource.Resource
|
||||
signatures: ['css.PostCSS [OPTIONS] RESOURCE']
|
||||
---
|
||||
|
||||
{{< new-in 0.128.0 />}}
|
||||
|
@ -25,40 +22,40 @@ toc: true
|
|||
|
||||
Follow the steps below to transform CSS using any of the available [PostCSS plugins].
|
||||
|
||||
[postcss plugins]: https://postcss.org/docs/postcss-plugins
|
||||
### Step 1
|
||||
|
||||
Step 1
|
||||
: Install [Node.js].
|
||||
Install [Node.js].
|
||||
|
||||
[node.js]: https://nodejs.org/en/download
|
||||
### Step 2
|
||||
|
||||
Step 2
|
||||
: Install the required Node.js packages in the root of your project. For example, to add vendor prefixes to your CSS rules:
|
||||
Install the required Node.js packages in the root of your project. For example, to add vendor prefixes to your CSS rules:
|
||||
|
||||
```sh
|
||||
npm i -D postcss postcss-cli autoprefixer
|
||||
```
|
||||
|
||||
Step 3
|
||||
: Create a PostCSS configuration file in the root of your project.
|
||||
### Step 3
|
||||
|
||||
{{< code file=postcss.config.js >}}
|
||||
Create a PostCSS configuration file in the root of your project.
|
||||
|
||||
```js {file="postcss.config.js"}
|
||||
module.exports = {
|
||||
plugins: [
|
||||
require('autoprefixer')
|
||||
]
|
||||
};
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
{{% include "functions/resources/_common/postcss-windows-warning.md" %}}
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> If you are a Windows user, and the path to your project contains a space, you must place the PostCSS configuration within the package.json file. See [this example] and issue [#7333].
|
||||
|
||||
Step 4
|
||||
: Place your CSS file within the `assets/css` directory.
|
||||
### Step 4
|
||||
|
||||
Step 5
|
||||
: Process the resource with PostCSS:
|
||||
Place your CSS file within the `assets/css` directory.
|
||||
|
||||
### Step 5
|
||||
|
||||
Process the resource with PostCSS:
|
||||
|
||||
```go-html-template
|
||||
{{ with resources.Get "css/main.css" | postCSS }}
|
||||
|
@ -74,13 +71,13 @@ config
|
|||
: (`string`) The directory that contains the PostCSS configuration file. Default is the root of the project directory.
|
||||
|
||||
noMap
|
||||
: (`bool`) Default is `false`. If `true`, disables inline sourcemaps.
|
||||
: (`bool`) Whether to disable inline source maps. Default is `false`.
|
||||
|
||||
inlineImports
|
||||
: (`bool`) Default is `false`. Enable inlining of @import statements. It does so recursively, but will only import a file once. URL imports (e.g. `@import url('https://fonts.googleapis.com/css?family=Open+Sans&display=swap');`) and imports with media queries will be ignored. Note that this import routine does not care about the CSS spec, so you can have @import anywhere in the file. Hugo will look for imports relative to the module mount and will respect theme overrides.
|
||||
: (`bool`) Whether to enable inlining of import statements. It does so recursively, but will only import a file once. URL imports (e.g. `@import url('https://fonts.googleapis.com/css?family=Open+Sans&display=swap');`) and imports with media queries will be ignored. Note that this import routine does not care about the CSS spec, so you can have @import anywhere in the file. Hugo will look for imports relative to the module mount and will respect theme overrides. Default is `false`.
|
||||
|
||||
skipInlineImportsNotFound
|
||||
: (`bool`) Default is `false`. Before Hugo 0.99.0 when `inlineImports` was enabled and we failed to resolve an import, we logged it as a warning. We now fail the build. If you have regular CSS imports in your CSS that you want to preserve, you can either use imports with URL or media queries (Hugo does not try to resolve those) or set `skipInlineImportsNotFound` to true.
|
||||
: (`bool`) Whether to allow the build process to continue despite unresolved import statements, preserving the original import declarations. If you have regular CSS imports in your CSS that you want to preserve, you can either use imports with URL or media queries (Hugo does not try to resolve those) or set this option to `true`. Default is `false`."
|
||||
|
||||
```go-html-template
|
||||
{{ $opts := dict "config" "config-directory" "noMap" true }}
|
||||
|
@ -124,3 +121,8 @@ module.exports = {
|
|||
]
|
||||
}
|
||||
```
|
||||
|
||||
[#7333]: https://github.com/gohugoio/hugo/issues/7333
|
||||
[Node.js]: https://nodejs.org/en
|
||||
[PostCSS plugins]: https://postcss.org/docs/postcss-plugins
|
||||
[this example]: https://github.com/postcss/postcss-load-config#packagejson
|
||||
|
|
|
@ -3,16 +3,11 @@ title: css.Sass
|
|||
description: Transpiles Sass to CSS.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [toCSS]
|
||||
related:
|
||||
- functions/resources/Fingerprint
|
||||
- functions/resources/Minify
|
||||
- functions/css/PostCSS
|
||||
- functions/resources/PostProcess
|
||||
returnType: resource.Resource
|
||||
signatures: ['css.Sass [OPTIONS] RESOURCE']
|
||||
toc: true
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [toCSS]
|
||||
returnType: resource.Resource
|
||||
signatures: ['css.Sass [OPTIONS] RESOURCE']
|
||||
---
|
||||
|
||||
{{< new-in 0.128.0 />}}
|
||||
|
@ -70,10 +65,10 @@ precision
|
|||
: (`int`) Precision of floating point math. Not applicable to Dart Sass.
|
||||
|
||||
enableSourceMap
|
||||
: (`bool`) If `true`, generates a source map.
|
||||
: (`bool`) Whether to generate a source map. Default is `false`.
|
||||
|
||||
sourceMapIncludeSources
|
||||
: (`bool`) If `true`, embeds sources in the generated source map. Not applicable to LibSass.
|
||||
: (`bool`) Whether to embed sources in the generated source map. Not applicable to LibSass. Default is `false`.
|
||||
|
||||
includePaths
|
||||
: (`slice`) A slice of paths, relative to the project root, that the transpiler will use when resolving `@use` and `@import` statements.
|
||||
|
@ -128,7 +123,7 @@ Run `hugo env` to list the active transpilers.
|
|||
|
||||
### Installing in a production environment
|
||||
|
||||
For [CI/CD] deployments (e.g., GitHub Pages, GitLab Pages, Netlify, etc.) you must edit the workflow to install Dart Sass before Hugo builds the site[^2]. Some providers allow you to use one of the package managers above, or you can download and extract one of the prebuilt binaries.
|
||||
For [CI/CD](g) deployments (e.g., GitHub Pages, GitLab Pages, Netlify, etc.) you must edit the workflow to install Dart Sass before Hugo builds the site[^2]. Some providers allow you to use one of the package managers above, or you can download and extract one of the prebuilt binaries.
|
||||
|
||||
[^2]: You do not have to do this if (a) you have not modified the assets cache location, and (b) you have not set `useResourceCacheWhen` to `never` in your [site configuration], and (c) you add and commit your `resources` directory to your repository.
|
||||
|
||||
|
@ -149,8 +144,8 @@ To install Dart Sass for your builds on GitLab Pages, the `.gitlab-ci.yml` file
|
|||
|
||||
```yaml
|
||||
variables:
|
||||
HUGO_VERSION: 0.141.0
|
||||
DART_SASS_VERSION: 1.83.4
|
||||
HUGO_VERSION: 0.144.2
|
||||
DART_SASS_VERSION: 1.85.0
|
||||
GIT_DEPTH: 0
|
||||
GIT_STRATEGY: clone
|
||||
GIT_SUBMODULE_STRATEGY: recursive
|
||||
|
@ -183,8 +178,8 @@ To install Dart Sass for your builds on Netlify, the `netlify.toml` file should
|
|||
|
||||
```toml
|
||||
[build.environment]
|
||||
HUGO_VERSION = "0.141.0"
|
||||
DART_SASS_VERSION = "1.83.4"
|
||||
HUGO_VERSION = "0.144.2"
|
||||
DART_SASS_VERSION = "1.85.0"
|
||||
NODE_VERSION = "22"
|
||||
TZ = "America/Los_Angeles"
|
||||
|
||||
|
@ -229,12 +224,11 @@ If you build Hugo from source and run `mage test -v`, the test will fail if you
|
|||
|
||||
[brew.sh]: https://brew.sh/
|
||||
[chocolatey.org]: https://community.chocolatey.org/packages/sass
|
||||
[ci/cd]: https://en.wikipedia.org/wiki/CI/CD
|
||||
[dart sass]: https://sass-lang.com/dart-sass
|
||||
[libsass]: https://sass-lang.com/libsass
|
||||
[prebuilt binaries]: https://github.com/sass/dart-sass/releases/latest
|
||||
[scoop.sh]: https://scoop.sh/#/apps?q=sass
|
||||
[site configuration]: /getting-started/configuration/#configure-build
|
||||
[site configuration]: /configuration/build/
|
||||
[snap package]: /installation/linux/#snap
|
||||
[snapcraft.io]: https://snapcraft.io/dart-sass
|
||||
[starter workflow]: https://github.com/actions/starter-workflows/blob/main/pages/hugo.yml
|
||||
|
|
|
@ -3,28 +3,27 @@ title: css.TailwindCSS
|
|||
description: Processes the given resource with the Tailwind CSS CLI.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/resources/Fingerprint
|
||||
- functions/resources/Minify
|
||||
- functions/css/PostCSS
|
||||
returnType: resource.Resource
|
||||
signatures: ['css.TailwindCSS [OPTIONS] RESOURCE']
|
||||
toc: true
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: []
|
||||
returnType: resource.Resource
|
||||
signatures: ['css.TailwindCSS [OPTIONS] RESOURCE']
|
||||
---
|
||||
|
||||
{{< new-in 0.128.0 />}}
|
||||
|
||||
Use the `css.TailwindCSS` function to process your Tailwind CSS files. This function uses the Tailwind CSS CLI to:
|
||||
Use the `css.TailwindCSS` function to process your Tailwind CSS files. This function uses the Tailwind CSS CLI to:
|
||||
|
||||
1. Scan your templates for Tailwind CSS utility class usage.
|
||||
1. Compile those utility classes into standard CSS.
|
||||
1. Generate an optimized CSS output file.
|
||||
|
||||
> [!caution]
|
||||
> Tailwind CSS v4.0 and later requires a relatively [modern browser](https://tailwindcss.com/docs/compatibility#browser-support) to render correctly.
|
||||
|
||||
## Setup
|
||||
|
||||
###### Step 1
|
||||
### Step 1
|
||||
|
||||
Install the Tailwind CSS CLI v4.0 or later:
|
||||
|
||||
|
@ -36,7 +35,7 @@ The TailwindCSS CLI is also available as a [standalone executable] if you want t
|
|||
|
||||
[standalone executable]: https://github.com/tailwindlabs/tailwindcss/releases/latest
|
||||
|
||||
###### Step 2
|
||||
### Step 2
|
||||
|
||||
Add this to your site configuration:
|
||||
|
||||
|
@ -58,23 +57,22 @@ source = "(postcss|tailwind)\\.config\\.js"
|
|||
target = "css"
|
||||
{{< /code-toggle >}}
|
||||
|
||||
|
||||
###### Step 3
|
||||
### Step 3
|
||||
|
||||
Create a CSS entry file:
|
||||
|
||||
{{< code file=assets/css/main.css copy=true >}}
|
||||
```css {file="assets/css/main.css" copy=true}
|
||||
@import "tailwindcss";
|
||||
@source "hugo_stats.json";
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
Tailwind CSS respects `.gitignore` files. This means that if `hugo_stats.json` is listed in your `.gitignore` file, Tailwind CSS will ignore it. To make `hugo_stats.json` available to Tailwind CSS you must explicitly source it as shown in the example above.
|
||||
|
||||
###### Step 4
|
||||
### Step 4
|
||||
|
||||
Create a partial template to process the CSS with the Tailwind CSS CLI:
|
||||
|
||||
{{< code file=layouts/partials/css.html copy=true >}}
|
||||
```go-html-template {file="layouts/partials/css.html" copy=true}
|
||||
{{ with (templates.Defer (dict "key" "global")) }}
|
||||
{{ with resources.Get "css/main.css" }}
|
||||
{{ $opts := dict
|
||||
|
@ -92,21 +90,21 @@ Create a partial template to process the CSS with the Tailwind CSS CLI:
|
|||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
###### Step 5
|
||||
### Step 5
|
||||
|
||||
Call the partial template from your base template:
|
||||
|
||||
{{< code file=layouts/default/baseof.html >}}
|
||||
```go-html-template {file="layouts/_default/baseof.html"}
|
||||
<head>
|
||||
...
|
||||
{{ partialCached "css.html" . }}
|
||||
...
|
||||
<head>
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
###### Step 6
|
||||
### Step 6
|
||||
|
||||
Optionally create a `tailwind.config.js` file in the root of your project as shown below. This is necessary if you use the [Tailwind CSS IntelliSense
|
||||
extension] for Visual Studio Code.
|
||||
|
@ -114,7 +112,7 @@ extension] for Visual Studio Code.
|
|||
[Tailwind CSS IntelliSense
|
||||
extension]: https://marketplace.visualstudio.com/items?itemName=bradlc.vscode-tailwindcss
|
||||
|
||||
{{< code file=tailwind.config.js copy=true >}}
|
||||
```js {file="tailwind.config.js" copy=true}
|
||||
/*
|
||||
This file is present to satisfy a requirement of the Tailwind CSS IntelliSense
|
||||
extension for Visual Studio Code.
|
||||
|
@ -123,7 +121,7 @@ https://marketplace.visualstudio.com/items?itemName=bradlc.vscode-tailwindcss
|
|||
|
||||
The rest of this file is intentionally empty.
|
||||
*/
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
|
@ -137,4 +135,4 @@ inlineImports
|
|||
: (`bool`) Whether to enable inlining of `@import` statements. Inlining is performed recursively, but currently once only per file. It is not possible to import the same file in different scopes (root, media query, etc.). Note that this import routine does not care about the CSS specification, so you can have `@import` statements anywhere in the file. Default is `false`.
|
||||
|
||||
skipInlineImportsNotFound
|
||||
: (`bool`) When `inlineImports` is enabled, we fail the build if an import cannot be resolved. Enable this option to allow the build to continue and leave the import statement in place. Note that the inline importer does not process URL location or imports with media queries, so those will be left as-is even without enabling this option. Default is `false`.
|
||||
: (`bool`) Whether to allow the build process to continue despite unresolved import statements, preserving the original import declarations. It is important to note that the inline importer does not process URL-based imports or those with media queries, and these will remain unaltered even when this option is disabled. Default is `false`.
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
---
|
||||
title: CSS functions
|
||||
linkTitle: css
|
||||
description: Template functions to work with CSS and Sass files.
|
||||
description: Use these functions to work with CSS and Sass files.
|
||||
categories: []
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
---
|
||||
|
||||
Use these functions to work with CSS and Sass files.
|
||||
|
|
|
@ -3,23 +3,22 @@ title: data.GetCSV
|
|||
description: Returns an array of arrays from a local or remote CSV file, or an error if the file does not exist.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [getCSV]
|
||||
related: []
|
||||
returnType: '[][]string'
|
||||
signatures: ['data.GetCSV SEPARATOR INPUT... [OPTIONS]']
|
||||
toc: true
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [getCSV]
|
||||
returnType: '[][]string'
|
||||
signatures: ['data.GetCSV SEPARATOR INPUT... [OPTIONS]']
|
||||
expiryDate: 2026-02-19 # deprecated 2024-02-19 in v0.123.0
|
||||
---
|
||||
|
||||
{{% deprecated-in 0.123.0 %}}
|
||||
{{< deprecated-in 0.123.0 >}}
|
||||
Instead, use [`transform.Unmarshal`] with a [global resource](g), [page resource](g), or [remote resource](g).
|
||||
|
||||
See the [remote data example].
|
||||
|
||||
[`transform.Unmarshal`]: /functions/transform/unmarshal/
|
||||
[remote data example]: /functions/resources/getremote/#remote-data
|
||||
{{% /deprecated-in %}}
|
||||
{{< /deprecated-in >}}
|
||||
|
||||
Given the following directory structure:
|
||||
|
||||
|
@ -36,11 +35,10 @@ Access the data with either of the following:
|
|||
{{ $data := getCSV "," "other-files/" "pets.csv" }}
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
When working with local data, the file path is relative to the working directory.
|
||||
|
||||
You must not place CSV files in the project's `data` directory.
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> When working with local data, the file path is relative to the working directory.
|
||||
>
|
||||
> You must not place CSV files in the project's `data` directory.
|
||||
|
||||
Access remote data with either of the following:
|
||||
|
||||
|
|
|
@ -3,23 +3,22 @@ title: data.GetJSON
|
|||
description: Returns a JSON object from a local or remote JSON file, or an error if the file does not exist.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [getJSON]
|
||||
related: []
|
||||
returnType: any
|
||||
signatures: ['data.GetJSON INPUT... [OPTIONS]']
|
||||
toc: true
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [getJSON]
|
||||
returnType: any
|
||||
signatures: ['data.GetJSON INPUT... [OPTIONS]']
|
||||
expiryDate: 2026-02-19 # deprecated 2024-02-19 in v0.123.0
|
||||
---
|
||||
|
||||
{{% deprecated-in 0.123.0 %}}
|
||||
{{< deprecated-in 0.123.0 >}}
|
||||
Instead, use [`transform.Unmarshal`] with a [global resource](g), [page resource](g), or [remote resource](g).
|
||||
|
||||
See the [remote data example].
|
||||
|
||||
[`transform.Unmarshal`]: /functions/transform/unmarshal/
|
||||
[remote data example]: /functions/resources/getremote/#remote-data
|
||||
{{% /deprecated-in %}}
|
||||
{{< /deprecated-in >}}
|
||||
|
||||
Given the following directory structure:
|
||||
|
||||
|
@ -36,9 +35,8 @@ Access the data with either of the following:
|
|||
{{ $data := getJSON "other-files/" "books.json" }}
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
When working with local data, the file path is relative to the working directory.
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> When working with local data, the file path is relative to the working directory.
|
||||
|
||||
Access remote data with either of the following:
|
||||
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
---
|
||||
title: Data functions
|
||||
linkTitle: data
|
||||
description: Template functions to read local or remote data files.
|
||||
description: Use these functions to read local or remote data files.
|
||||
categories: []
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
---
|
||||
|
||||
Use these functions to read local or remote data files.
|
||||
|
|
|
@ -3,11 +3,11 @@ title: debug.Dump
|
|||
description: Returns an object dump as a string.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related: []
|
||||
returnType: string
|
||||
signatures: [debug.Dump VALUE]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: []
|
||||
returnType: string
|
||||
signatures: [debug.Dump VALUE]
|
||||
---
|
||||
|
||||
```go-html-template
|
||||
|
@ -29,6 +29,5 @@ action:
|
|||
]
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
Output from this function may change from one release to the next. Use for debugging only.
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> Output from this function may change from one release to the next. Use for debugging only.
|
||||
|
|
|
@ -3,11 +3,11 @@ title: debug.Timer
|
|||
description: Creates a named timer that reports elapsed time to the console.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related: []
|
||||
returnType: debug.Timer
|
||||
signatures: [debug.Timer NAME]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: []
|
||||
returnType: debug.Timer
|
||||
signatures: [debug.Timer NAME]
|
||||
---
|
||||
|
||||
{{< new-in 0.120.0 />}}
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
---
|
||||
title: Debug functions
|
||||
linkTitle: debug
|
||||
description: Template functions to debug your templates.
|
||||
description: Use these functions to debug your templates.
|
||||
categories: []
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
---
|
||||
|
||||
Use these functions to debug your templates.
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
---
|
||||
title: diagrams.Goat
|
||||
description: Converts ASCII art to an SVG diagram, returning a GoAT diagram object.
|
||||
description: Returns an SVGDiagram object created from the given GoAT markup and options.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related: []
|
||||
returnType: diagrams.goatDiagram
|
||||
signatures: ['diagrams.Goat INPUT']
|
||||
toc: true
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: []
|
||||
returnType: diagrams.SVGDiagram
|
||||
signatures: [diagrams.Goat MARKUP]
|
||||
---
|
||||
|
||||
Useful in a [code block render hook], the `diagram.Goat` function converts ASCII art to an SVG diagram, returning a [GoAT] diagram object with the following methods:
|
||||
Useful in a [code block render hook], the `diagrams.Goat` function returns an SVGDiagram object created from the given [GoAT] markup.
|
||||
|
||||
[GoAT]: https://github.com/blampe/goat#readme
|
||||
[code block render hook]: /render-hooks/code-blocks/
|
||||
## Methods
|
||||
|
||||
The SVGDiagram object has the following methods:
|
||||
|
||||
Inner
|
||||
: (`template.HTML`) Returns the SVG child elements without a wrapping `svg` element, allowing you to create your own wrapper.
|
||||
|
@ -30,13 +30,11 @@ Height
|
|||
|
||||
## GoAT Diagrams
|
||||
|
||||
Hugo natively supports [GoAT](https://github.com/bep/goat) diagrams with an [embedded code block render hook].
|
||||
|
||||
[embedded code block render hook]: {{% eturl render-codeblock-goat %}}
|
||||
Hugo natively supports GoAT diagrams with an [embedded code block render hook].
|
||||
|
||||
This Markdown:
|
||||
|
||||
````
|
||||
````text
|
||||
```goat
|
||||
.---. .-. .-. .-. .---.
|
||||
| A +--->| 1 |<--->| 2 |<--->| 3 |<---+ B |
|
||||
|
@ -68,7 +66,7 @@ To customize rendering, override Hugo's [embedded code block render hook] for Go
|
|||
|
||||
By way of example, let's create a code block render hook to render GoAT diagrams as `figure` elements with an optional caption.
|
||||
|
||||
{{< code file=layouts/_default/_markup/render-codeblock-goat.html >}}
|
||||
```go-html-template {file="layouts/_default/_markup/render-codeblock-goat.html"}
|
||||
{{ $caption := or .Attributes.caption "" }}
|
||||
{{ $class := or .Attributes.class "diagram" }}
|
||||
{{ $id := or .Attributes.id (printf "diagram-%d" (add 1 .Ordinal)) }}
|
||||
|
@ -81,17 +79,17 @@ By way of example, let's create a code block render hook to render GoAT diagrams
|
|||
{{ end }}
|
||||
<figcaption>{{ $caption }}</figcaption>
|
||||
</figure>
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
This Markdown:
|
||||
|
||||
{{< code file=content/example.md lang=text >}}
|
||||
````text {file="content/example.md" }
|
||||
```goat {class="foo" caption="Diagram 1: Example"}
|
||||
.---. .-. .-. .-. .---.
|
||||
| A +--->| 1 |<--->| 2 |<--->| 3 |<---+ B |
|
||||
'---' '-' '+' '+' '---'
|
||||
```
|
||||
{{< /code >}}
|
||||
````
|
||||
|
||||
Is rendered to:
|
||||
|
||||
|
@ -111,3 +109,7 @@ svg.foo {
|
|||
font-family: "Segoe UI","Noto Sans",Helvetica,Arial,sans-serif
|
||||
}
|
||||
```
|
||||
|
||||
[code block render hook]: /render-hooks/code-blocks/
|
||||
[embedded code block render hook]: {{% eturl render-codeblock-goat %}}
|
||||
[GoAT]: https://github.com/bep/goat
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
---
|
||||
title: Diagram functions
|
||||
linkTitle: diagrams
|
||||
description: Template functions to render diagrams.
|
||||
description: Use these functions to render diagrams.
|
||||
categories: []
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
---
|
||||
|
||||
Use these functions to render diagrams.
|
||||
|
|
|
@ -3,12 +3,11 @@ title: encoding.Base64Decode
|
|||
description: Returns the base64 decoding of the given content.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [base64Decode]
|
||||
related:
|
||||
- functions/encoding/Base64Encode
|
||||
returnType: string
|
||||
signatures: [encoding.Base64Decode INPUT]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [base64Decode]
|
||||
returnType: string
|
||||
signatures: [encoding.Base64Decode INPUT]
|
||||
aliases: [/functions/base64Decode]
|
||||
---
|
||||
|
||||
|
@ -29,7 +28,7 @@ To retrieve and render the content:
|
|||
{{ with try (resources.GetRemote $url) }}
|
||||
{{ with .Err }}
|
||||
{{ errorf "%s" . }}
|
||||
{{ else with .Value}}
|
||||
{{ else with .Value }}
|
||||
{{ with . | transform.Unmarshal }}
|
||||
{{ .content | base64Decode | markdownify }}
|
||||
{{ end }}
|
||||
|
|
|
@ -3,12 +3,11 @@ title: encoding.Base64Encode
|
|||
description: Returns the base64 decoding of the given content.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [base64Encode]
|
||||
related:
|
||||
- functions/encoding/Base64Decode
|
||||
returnType: string
|
||||
signatures: [encoding.Base64Encode INPUT]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [base64Encode]
|
||||
returnType: string
|
||||
signatures: [encoding.Base64Encode INPUT]
|
||||
aliases: [/functions/base64, /functions/base64Encode]
|
||||
---
|
||||
|
||||
|
|
|
@ -3,14 +3,11 @@ title: encoding.Jsonify
|
|||
description: Encodes the given object to JSON.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [jsonify]
|
||||
returnType: template.HTML
|
||||
related:
|
||||
- functions/transform/Remarshal
|
||||
- functions/transform/Unmarshal
|
||||
signatures:
|
||||
- encoding.Jsonify [OPTIONS] INPUT
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [jsonify]
|
||||
returnType: template.HTML
|
||||
signatures: ['encoding.Jsonify [OPTIONS] INPUT']
|
||||
aliases: [/functions/jsonify]
|
||||
---
|
||||
|
||||
|
@ -34,4 +31,4 @@ prefix
|
|||
: (`string`) Indentation prefix. Default is "".
|
||||
|
||||
noHTMLEscape
|
||||
: (`bool`) Disable escaping of problematic HTML characters inside JSON quoted strings. The default behavior is to escape `&`, `<`, and `>` to `\u0026`, `\u003c`, and `\u003e` to avoid certain safety problems that can arise when embedding JSON in HTML. Default is `false`.
|
||||
: (`bool`) Whether to disable escaping of problematic HTML characters inside JSON quoted strings. The default behavior is to escape `&`, `<`, and `>` to `\u0026`, `\u003c`, and `\u003e` to avoid certain safety problems that can arise when embedding JSON in HTML. Default is `false`.
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
---
|
||||
title: Encoding functions
|
||||
linkTitle: encoding
|
||||
description: Template functions to encode and decode data.
|
||||
description: Use these functions to encode and decode data.
|
||||
categories: []
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
---
|
||||
|
||||
Use these functions to encode and decode data.
|
||||
|
|
|
@ -3,18 +3,15 @@ title: fmt.Errorf
|
|||
description: Log an ERROR from a template.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [errorf]
|
||||
related:
|
||||
- functions/fmt/Erroridf
|
||||
- functions/fmt/Warnf
|
||||
- functions/fmt/Warnidf
|
||||
returnType: string
|
||||
signatures: ['fmt.Errorf FORMAT [INPUT]']
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [errorf]
|
||||
returnType: string
|
||||
signatures: ['fmt.Errorf FORMAT [INPUT]']
|
||||
aliases: [/functions/errorf]
|
||||
---
|
||||
|
||||
{{% include "functions/fmt/_common/fmt-layout.md" %}}
|
||||
{{% include "/_common/functions/fmt/format-string.md" %}}
|
||||
|
||||
The `errorf` function evaluates the format string, then prints the result to the ERROR log and fails the build.
|
||||
|
||||
|
|
|
@ -3,18 +3,15 @@ title: fmt.Erroridf
|
|||
description: Log a suppressible ERROR from a template.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [erroridf]
|
||||
related:
|
||||
- functions/fmt/Errorf
|
||||
- functions/fmt/Warnf
|
||||
- functions/fmt/Warnidf
|
||||
returnType: string
|
||||
signatures: ['fmt.Erroridf ID FORMAT [INPUT]']
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [erroridf]
|
||||
returnType: string
|
||||
signatures: ['fmt.Erroridf ID FORMAT [INPUT]']
|
||||
aliases: [/functions/erroridf]
|
||||
---
|
||||
|
||||
{{% include "functions/fmt/_common/fmt-layout.md" %}}
|
||||
{{% include "/_common/functions/fmt/format-string.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 `ignoreLogs` array in your site configuration.
|
||||
|
||||
|
|
|
@ -3,13 +3,11 @@ 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]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [print]
|
||||
returnType: string
|
||||
signatures: [fmt.Print INPUT]
|
||||
aliases: [/functions/print]
|
||||
---
|
||||
|
||||
|
|
|
@ -3,17 +3,15 @@ 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]']
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [printf]
|
||||
returnType: string
|
||||
signatures: ['fmt.Printf FORMAT [INPUT]']
|
||||
aliases: [/functions/printf]
|
||||
---
|
||||
|
||||
{{% include "functions/fmt/_common/fmt-layout.md" %}}
|
||||
{{% include "/_common/functions/fmt/format-string.md" %}}
|
||||
|
||||
```go-html-template
|
||||
{{ $var := "world" }}
|
||||
|
|
|
@ -3,13 +3,11 @@ 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]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [println]
|
||||
returnType: string
|
||||
signatures: [fmt.Println INPUT]
|
||||
aliases: [/functions/println]
|
||||
---
|
||||
|
||||
|
|
|
@ -3,18 +3,15 @@ title: fmt.Warnf
|
|||
description: Log a WARNING from a template.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [warnf]
|
||||
related:
|
||||
- functions/fmt/Errorf
|
||||
- functions/fmt/Erroridf
|
||||
- functions/fmt/Warnidf
|
||||
returnType: string
|
||||
signatures: ['fmt.Warnf FORMAT [INPUT]']
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [warnf]
|
||||
returnType: string
|
||||
signatures: ['fmt.Warnf FORMAT [INPUT]']
|
||||
aliases: [/functions/warnf]
|
||||
---
|
||||
|
||||
{{% include "functions/fmt/_common/fmt-layout.md" %}}
|
||||
{{% include "/_common/functions/fmt/format-string.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.
|
||||
|
||||
|
|
|
@ -3,20 +3,17 @@ title: fmt.Warnidf
|
|||
description: Log a suppressible WARNING from a template.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [warnidf]
|
||||
related:
|
||||
- functions/fmt/Errorf
|
||||
- functions/fmt/Erroridf
|
||||
- functions/fmt/Warnf
|
||||
returnType: string
|
||||
signatures: ['fmt.Warnidf ID FORMAT [INPUT]']
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [warnidf]
|
||||
returnType: string
|
||||
signatures: ['fmt.Warnidf ID FORMAT [INPUT]']
|
||||
aliases: [/functions/warnidf]
|
||||
---
|
||||
|
||||
{{< new-in 0.123.0 />}}
|
||||
|
||||
{{% include "functions/fmt/_common/fmt-layout.md" %}}
|
||||
{{% include "/_common/functions/fmt/format-string.md" %}}
|
||||
|
||||
The `warnidf` function evaluates the format string, then prints the result to the WARNING log. Unlike the [`warnf`] function, you may suppress warnings logged by the `warnidf` function by adding the message ID to the `ignoreLogs` array in your site configuration.
|
||||
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
---
|
||||
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.
|
||||
-->
|
|
@ -1,7 +0,0 @@
|
|||
---
|
||||
_comment: 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
|
|
@ -1,12 +1,7 @@
|
|||
---
|
||||
title: Fmt functions
|
||||
linkTitle: fmt
|
||||
description: Template functions to print strings within a template or to print messages to the terminal
|
||||
description: Use these 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.
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
---
|
||||
title: Global functions
|
||||
linkTitle: global
|
||||
description: Global template functions to access page and site data.
|
||||
description: Use these global functions to access page and site data.
|
||||
categories: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
---
|
||||
|
||||
Use these global functions to access page and site data.
|
||||
|
|
|
@ -3,13 +3,11 @@ title: page
|
|||
description: Provides global access to a Page object.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/global/site
|
||||
returnType:
|
||||
signatures: [page]
|
||||
toc: true
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: []
|
||||
returnType:
|
||||
signatures: [page]
|
||||
aliases: [/functions/page]
|
||||
---
|
||||
|
||||
|
@ -27,13 +25,12 @@ When a `Page` object is not in context, you can use the global `page` function:
|
|||
{{ page.Params.foo }}
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
Do not use the global `page` function in shortcodes, partials called by shortcodes, or cached partials. See [warnings](#warnings) below.
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> Do not use the global `page` function in shortcodes, partials called by shortcodes, or cached partials. See [warnings](#warnings) below.
|
||||
|
||||
## Explanation
|
||||
|
||||
Hugo almost always passes a `Page` as the data context into the top level template (e.g., `single.html`). The one exception is the multihost sitemap template. This means that you can access the current page with the `.` in the template.
|
||||
Hugo almost always passes a `Page` as the data context into the top-level template (e.g., `single.html`). The one exception is the multihost sitemap template. This means that you can access the current page with the `.` in the template.
|
||||
|
||||
But when you are deeply nested inside of a [content view](g), [partial](g), or [render hook](g), it is not always practical or possible to access the `Page` object.
|
||||
|
||||
|
@ -99,5 +96,5 @@ When you call the [`Summary`] method, Hugo renders the page content including sh
|
|||
|
||||
If Hugo renders the section page before a content page, the cached rendered shortcode will be incorrect. You cannot control the rendering sequence due to concurrency.
|
||||
|
||||
[`Summary`]: /methods/page/summary/
|
||||
[`partialCached`]: /functions/partials/includecached/
|
||||
[`Summary`]: /methods/page/summary/
|
||||
|
|
|
@ -3,12 +3,11 @@ title: site
|
|||
description: Provides global access to the current Site object.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/global/page
|
||||
returnType:
|
||||
signatures: [site]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: []
|
||||
returnType:
|
||||
signatures: [site]
|
||||
aliases: [/functions/site]
|
||||
---
|
||||
|
||||
|
@ -27,6 +26,5 @@ When the `Site` object is in context you can use the `Site` property:
|
|||
{{ $.Site.Params.foo }}
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
To simplify your templates, use the global `site` function regardless of whether the `Site` object is in context.
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> To simplify your templates, use the global `site` function regardless of whether the `Site` object is in context.
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
---
|
||||
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.
|
||||
-->
|
|
@ -1,7 +0,0 @@
|
|||
---
|
||||
_comment: Do not remove front matter.
|
||||
---
|
||||
|
||||
See Go's [text/template] documentation for more information.
|
||||
|
||||
[text/template]: https://pkg.go.dev/text/template
|
|
@ -1,7 +0,0 @@
|
|||
---
|
||||
_comment: Do not remove front matter.
|
||||
---
|
||||
|
||||
The falsy values are `false`, `0`, any `nil` pointer or interface value, any array, slice, map, or string of length zero, and zero `time.Time` values.
|
||||
|
||||
Everything else is truthy.
|
|
@ -1,14 +1,7 @@
|
|||
---
|
||||
title: Go template functions, operators, and statements
|
||||
linkTitle: go template
|
||||
description: Template functions, operators, and statements provided by Go's text/template package.
|
||||
description: These are the functions, operators, and statements provided by Go's text/template package.
|
||||
categories: []
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
---
|
||||
|
||||
These are the functions, operators, and statements provided by Go's [text/template] package.
|
||||
|
||||
[text/template]: https://pkg.go.dev/text/template
|
||||
|
|
|
@ -3,16 +3,14 @@ title: and
|
|||
description: Returns the first falsy argument. If all arguments are truthy, returns the last argument.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/go-template/not
|
||||
- functions/go-template/or
|
||||
returnType: any
|
||||
signatures: [and VALUE...]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: []
|
||||
returnType: any
|
||||
signatures: [and VALUE...]
|
||||
---
|
||||
|
||||
{{% include "functions/go-template/_common/truthy-falsy.md" %}}
|
||||
{{% include "/_common/functions/truthy-falsy.md" %}}
|
||||
|
||||
```go-html-template
|
||||
{{ and 1 0 "" }} → 0 (int)
|
||||
|
@ -22,5 +20,3 @@ action:
|
|||
{{ and "a" "b" "c" }} → c (string)
|
||||
{{ and "a" 1 true }} → true (bool)
|
||||
```
|
||||
|
||||
{{% include "functions/go-template/_common/text-template.md" %}}
|
||||
|
|
|
@ -3,13 +3,11 @@ title: block
|
|||
description: Defines a template and executes it in place.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/go-template/define
|
||||
- functions/go-template/end
|
||||
returnType:
|
||||
signatures: [block NAME CONTEXT]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: []
|
||||
returnType:
|
||||
signatures: [block NAME CONTEXT]
|
||||
---
|
||||
|
||||
A block is shorthand for defining a template:
|
||||
|
@ -25,7 +23,7 @@ and then executing it in place:
|
|||
```
|
||||
The typical use is to define a set of root templates that are then customized by redefining the block templates within.
|
||||
|
||||
{{< code file=layouts/_default/baseof.html >}}
|
||||
```go-html-template {file="layouts/_default/baseof.html"}
|
||||
<body>
|
||||
<main>
|
||||
{{ block "main" . }}
|
||||
|
@ -33,16 +31,16 @@ The typical use is to define a set of root templates that are then customized by
|
|||
{{ end }}
|
||||
</main>
|
||||
</body>
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
{{< code file=layouts/_default/single.html >}}
|
||||
```go-html-template {file="layouts/_default/single.html"}
|
||||
{{ define "main" }}
|
||||
<h1>{{ .Title }}</h1>
|
||||
{{ .Content }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
{{< code file=layouts/_default/list.html >}}
|
||||
```go-html-template {file="layouts/_default/list.html"}
|
||||
{{ define "main" }}
|
||||
<h1>{{ .Title }}</h1>
|
||||
{{ .Content }}
|
||||
|
@ -50,6 +48,6 @@ The typical use is to define a set of root templates that are then customized by
|
|||
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
{{% include "functions/go-template/_common/text-template.md" %}}
|
||||
{{% include "/_common/functions/go-template/text-template.md" %}}
|
||||
|
|
|
@ -3,13 +3,11 @@ title: break
|
|||
description: Used with the range statement, stops the innermost iteration and bypasses all remaining iterations.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/go-template/continue
|
||||
- functions/go-template/range
|
||||
returnType:
|
||||
signatures: [break]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: []
|
||||
returnType:
|
||||
signatures: [break]
|
||||
---
|
||||
|
||||
This template code:
|
||||
|
@ -30,4 +28,4 @@ Is rendered to:
|
|||
<p>foo</p>
|
||||
```
|
||||
|
||||
{{% include "functions/go-template/_common/text-template.md" %}}
|
||||
{{% include "/_common/functions/go-template/text-template.md" %}}
|
||||
|
|
|
@ -3,13 +3,11 @@ title: continue
|
|||
description: Used with the range statement, stops the innermost iteration and continues to the next iteration.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/go-template/break
|
||||
- functions/go-template/range
|
||||
returnType:
|
||||
signatures: [continue]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: []
|
||||
returnType:
|
||||
signatures: [continue]
|
||||
---
|
||||
|
||||
This template code:
|
||||
|
@ -31,4 +29,4 @@ Is rendered to:
|
|||
<p>baz</p>
|
||||
```
|
||||
|
||||
{{% include "functions/go-template/_common/text-template.md" %}}
|
||||
{{% include "/_common/functions/go-template/text-template.md" %}}
|
||||
|
|
|
@ -3,16 +3,11 @@ title: define
|
|||
description: Defines a template.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/go-template/block
|
||||
- functions/go-template/end
|
||||
- functions/go-template/template
|
||||
- functions/partials/Include
|
||||
- functions/partials/IncludeCached
|
||||
returnType:
|
||||
signatures: [define NAME]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: []
|
||||
returnType:
|
||||
signatures: [define NAME]
|
||||
---
|
||||
|
||||
Use with the [`block`] statement:
|
||||
|
@ -52,4 +47,4 @@ Use with the [`template`] function:
|
|||
[`template`]: /functions/go-template/block/
|
||||
[`partial`]: /functions/partials/include/
|
||||
|
||||
{{% include "functions/go-template/_common/text-template.md" %}}
|
||||
{{% include "/_common/functions/go-template/text-template.md" %}}
|
||||
|
|
|
@ -3,15 +3,11 @@ title: else
|
|||
description: Begins an alternate block for if, with, and range statements.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/go-template/if
|
||||
- functions/go-template/range
|
||||
- functions/go-template/with
|
||||
- functions/go-template/end
|
||||
returnType:
|
||||
signatures: [else VALUE]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: []
|
||||
returnType:
|
||||
signatures: [else VALUE]
|
||||
---
|
||||
|
||||
Use with the [`if`] statement:
|
||||
|
@ -62,7 +58,7 @@ Use `else if` to check multiple conditions.
|
|||
{{ end }}
|
||||
```
|
||||
|
||||
{{% include "functions/go-template/_common/text-template.md" %}}
|
||||
{{% include "/_common/functions/go-template/text-template.md" %}}
|
||||
|
||||
[`if`]: /functions/go-template/if/
|
||||
[`with`]: /functions/go-template/with/
|
||||
|
|
|
@ -3,16 +3,11 @@ title: end
|
|||
description: Terminates if, with, range, block, and define statements.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/go-template/block
|
||||
- functions/go-template/define
|
||||
- functions/go-template/if
|
||||
- functions/go-template/range
|
||||
- functions/go-template/with
|
||||
returnType:
|
||||
signatures: [end]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: []
|
||||
returnType:
|
||||
signatures: [end]
|
||||
---
|
||||
|
||||
Use with the [`if`] statement:
|
||||
|
@ -56,7 +51,7 @@ Use with the [`define`] statement:
|
|||
{{ end }}
|
||||
```
|
||||
|
||||
{{% include "functions/go-template/_common/text-template.md" %}}
|
||||
{{% include "/_common/functions/go-template/text-template.md" %}}
|
||||
|
||||
[`block`]: /functions/go-template/block/
|
||||
[`define`]: /functions/go-template/define/
|
||||
|
|
|
@ -3,18 +3,14 @@ title: if
|
|||
description: Executes the block if the expression is truthy.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/go-template/with
|
||||
- functions/go-template/else
|
||||
- functions/go-template/end
|
||||
- functions/collections/IsSet
|
||||
returnType:
|
||||
signatures: [if EXPR]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: []
|
||||
returnType:
|
||||
signatures: [if EXPR]
|
||||
---
|
||||
|
||||
{{% include "functions/go-template/_common/truthy-falsy.md" %}}
|
||||
{{% include "/_common/functions/truthy-falsy.md" %}}
|
||||
|
||||
```go-html-template
|
||||
{{ $var := "foo" }}
|
||||
|
@ -49,6 +45,6 @@ Use `else if` to check multiple conditions:
|
|||
{{ end }}
|
||||
```
|
||||
|
||||
{{% include "functions/go-template/_common/text-template.md" %}}
|
||||
{{% include "/_common/functions/go-template/text-template.md" %}}
|
||||
|
||||
[`else`]: /functions/go-template/else/
|
||||
|
|
|
@ -3,15 +3,11 @@ title: len
|
|||
description: Returns the length of a string, slice, map, or collection.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/strings/Count
|
||||
- functions/strings/CountRunes
|
||||
- functions/strings/CountWords
|
||||
- functions/strings/RuneCount
|
||||
returnType: int
|
||||
signatures: [len VALUE]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: []
|
||||
returnType: int
|
||||
signatures: [len VALUE]
|
||||
aliases: [/functions/len]
|
||||
---
|
||||
|
||||
|
@ -48,4 +44,4 @@ You may also determine the number of pages in a collection with:
|
|||
{{ site.RegularPages.Len }} → 42
|
||||
```
|
||||
|
||||
{{% include "functions/go-template/_common/text-template.md" %}}
|
||||
{{% include "/_common/functions/go-template/text-template.md" %}}
|
||||
|
|
|
@ -3,13 +3,11 @@ title: not
|
|||
description: Returns the boolean negation of its single argument.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/go-template/and
|
||||
- functions/go-template/or
|
||||
returnType: bool
|
||||
signatures: [not VALUE]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: []
|
||||
returnType: bool
|
||||
signatures: [not VALUE]
|
||||
---
|
||||
|
||||
Unlike the `and` and `or` operators, the `not` operator always returns a boolean value.
|
||||
|
@ -32,4 +30,4 @@ Use the `not` operator, twice in succession, to cast any value to a boolean valu
|
|||
{{ "" | not | not }} → false
|
||||
```
|
||||
|
||||
{{% include "functions/go-template/_common/text-template.md" %}}
|
||||
{{% include "/_common/functions/go-template/text-template.md" %}}
|
||||
|
|
|
@ -3,16 +3,14 @@ title: or
|
|||
description: Returns the first truthy argument. If all arguments are falsy, returns the last argument.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/go-template/and
|
||||
- functions/go-template/not
|
||||
returnType: any
|
||||
signatures: [or VALUE...]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: []
|
||||
returnType: any
|
||||
signatures: [or VALUE...]
|
||||
---
|
||||
|
||||
{{% include "functions/go-template/_common/truthy-falsy.md" %}}
|
||||
{{% include "/_common/functions/truthy-falsy.md" %}}
|
||||
|
||||
```go-html-template
|
||||
{{ or 0 1 2 }} → 1
|
||||
|
@ -23,4 +21,4 @@ action:
|
|||
{{ or 0 "" false }} → false
|
||||
```
|
||||
|
||||
{{% include "functions/go-template/_common/text-template.md" %}}
|
||||
{{% include "/_common/functions/go-template/text-template.md" %}}
|
||||
|
|
|
@ -3,20 +3,15 @@ title: range
|
|||
description: Iterates over a non-empty collection, binds context (the dot) to successive elements, and executes the block.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/go-template/break
|
||||
- functions/go-template/continue
|
||||
- functions/go-template/else
|
||||
- functions/go-template/end
|
||||
returnType:
|
||||
signatures: [range COLLECTION]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: []
|
||||
returnType:
|
||||
signatures: [range COLLECTION]
|
||||
aliases: [/functions/range]
|
||||
toc: true
|
||||
---
|
||||
|
||||
{{% include "functions/go-template/_common/truthy-falsy.md" %}}
|
||||
{{% include "/_common/functions/truthy-falsy.md" %}}
|
||||
|
||||
```go-html-template
|
||||
{{ $s := slice "foo" "bar" "baz" }}
|
||||
|
@ -59,9 +54,8 @@ Hugo will throw an error:
|
|||
|
||||
The error occurs because we are trying to use the `.Title` method on an integer instead of a `Page` object. Within the `range` block, if we want to render the page title, we need to get the context passed into the template.
|
||||
|
||||
{{% note %}}
|
||||
Use the `$` to get the context passed into the template.
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> Use the `$` to get the context passed into the template.
|
||||
|
||||
This template will render the page title three times:
|
||||
|
||||
|
@ -71,11 +65,8 @@ This template will render the page title three times:
|
|||
{{ end }}
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
Gaining a thorough understanding of context is critical for anyone writing template code.
|
||||
{{% /note %}}
|
||||
|
||||
[`seq`]: /functions/collections/seq/
|
||||
> [!note]
|
||||
> Gaining a thorough understanding of context is critical for anyone writing template code.
|
||||
|
||||
## Array or slice of scalars
|
||||
|
||||
|
@ -191,8 +182,9 @@ Is rendered to:
|
|||
|
||||
Unlike ranging over an array or slice, Hugo sorts by key when ranging over a map.
|
||||
|
||||
{{% include "functions/go-template/_common/text-template.md" %}}
|
||||
{{% include "/_common/functions/go-template/text-template.md" %}}
|
||||
|
||||
[`else`]: /functions/go-template/else/
|
||||
[`break`]: /functions/go-template/break/
|
||||
[`continue`]: /functions/go-template/continue/
|
||||
[`else`]: /functions/go-template/else/
|
||||
[`seq`]: /functions/collections/seq/
|
||||
|
|
|
@ -3,14 +3,11 @@ title: return
|
|||
description: Used within partial templates, terminates template execution and returns the given value, if any.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/partials/Include
|
||||
- functions/partials/IncludeCached
|
||||
returnType: any
|
||||
signatures: ['return [VALUE]']
|
||||
toc: true
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: []
|
||||
returnType: any
|
||||
signatures: ['return [VALUE]']
|
||||
---
|
||||
|
||||
The `return` statement is a non-standard extension to Go's [text/template package]. Used within partial templates, the `return` statement terminates template execution and returns the given value, if any.
|
||||
|
@ -19,21 +16,20 @@ The returned value may be of any data type including, but not limited to, [`bool
|
|||
|
||||
A `return` statement without a value returns an empty string of type `template.HTML`.
|
||||
|
||||
{{% note %}}
|
||||
Unlike `return` statements in other languages, Hugo executes the first occurrence of the `return` statement regardless of its position within logical blocks. See [usage](#usage) notes below.
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> Unlike `return` statements in other languages, Hugo executes the first occurrence of the `return` statement regardless of its position within logical blocks. See [usage](#usage) notes below.
|
||||
|
||||
## Example
|
||||
|
||||
By way of example, let's create a partial template that _renders_ HTML, describing whether the given number is odd or even:
|
||||
|
||||
{{< code file="layouts/partials/odd-or-even.html" >}}
|
||||
```go-html-template {file="layouts/partials/odd-or-even.html"}
|
||||
{{ if math.ModBool . 2 }}
|
||||
<p>{{ . }} is even</p>
|
||||
{{ else }}
|
||||
<p>{{ . }} is odd</p>
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
When called, the partial renders HTML:
|
||||
|
||||
|
@ -43,9 +39,9 @@ When called, the partial renders HTML:
|
|||
|
||||
Instead of rendering HTML, let's create a partial that _returns_ a boolean value, reporting whether the given number is even:
|
||||
|
||||
{{< code file="layouts/partials/is-even.html" >}}
|
||||
```go-html-template {file="layouts/partials/is-even.html"}
|
||||
{{ return math.ModBool . 2 }}
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
With this template:
|
||||
|
||||
|
@ -66,19 +62,16 @@ Hugo renders:
|
|||
|
||||
See additional examples in the [partial templates] section.
|
||||
|
||||
[partial templates]: /templates/partial/#returning-a-value-from-a-partial
|
||||
|
||||
## Usage
|
||||
|
||||
{{% note %}}
|
||||
Unlike `return` statements in other languages, Hugo executes the first occurrence of the `return` statement regardless of its position within logical blocks.
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> Unlike `return` statements in other languages, Hugo executes the first occurrence of the `return` statement regardless of its position within logical blocks.
|
||||
|
||||
A partial that returns a value must contain only one `return` statement, placed at the end of the template.
|
||||
|
||||
For example:
|
||||
|
||||
{{< code file="layouts/partials/is-even.html" >}}
|
||||
```go-html-template {file="layouts/partials/is-even.html"}
|
||||
{{ $result := false }}
|
||||
{{ if math.ModBool . 2 }}
|
||||
{{ $result = "even" }}
|
||||
|
@ -86,16 +79,18 @@ For example:
|
|||
{{ $result = "odd" }}
|
||||
{{ end }}
|
||||
{{ return $result }}
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
The construct below is incorrect; it contains more than one `return` statement.
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> The construct below is incorrect; it contains more than one `return` statement.
|
||||
|
||||
{{< code file="layouts/partials/do-not-do-this.html" >}}
|
||||
```go-html-template {file="layouts/partials/do-not-do-this.html"}
|
||||
{{ if math.ModBool . 2 }}
|
||||
{{ return "even" }}
|
||||
{{ else }}
|
||||
{{ return "odd" }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
[partial templates]: /templates/partial/#returning-a-value-from-a-partial
|
||||
[text/template package]: https://pkg.go.dev/text/template
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue