diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2024-12-11 09:53:33 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2024-12-11 09:53:33 +0100 |
commit | b47376586a50753c2ee1f02961d0b0c2280bbc9c (patch) | |
tree | 0b12e4ebdbd20570e6da9dd5ba36694a1377f2ff /docs/content/en/functions | |
parent | 5ab38de36387062a8ca6c1d18c6a773fa248519c (diff) | |
parent | e477373487abcccdbed95688e37aa74b9b8fc198 (diff) | |
download | hugo-b47376586a50753c2ee1f02961d0b0c2280bbc9c.tar.gz hugo-b47376586a50753c2ee1f02961d0b0c2280bbc9c.zip |
Merge commit 'e477373487abcccdbed95688e37aa74b9b8fc198'
Diffstat (limited to 'docs/content/en/functions')
16 files changed, 145 insertions, 20 deletions
diff --git a/docs/content/en/functions/_common/glob-patterns.md b/docs/content/en/functions/_common/glob-patterns.md index 3b0813f6f..d3092dece 100644 --- a/docs/content/en/functions/_common/glob-patterns.md +++ b/docs/content/en/functions/_common/glob-patterns.md @@ -1,5 +1,5 @@ --- -# Do not remove front matter. +_comment: Do not remove front matter. --- Path|Pattern|Match diff --git a/docs/content/en/functions/_common/go-html-template-package.md b/docs/content/en/functions/_common/go-html-template-package.md index b622f2b76..57992ea66 100644 --- a/docs/content/en/functions/_common/go-html-template-package.md +++ b/docs/content/en/functions/_common/go-html-template-package.md @@ -1,5 +1,5 @@ --- -# Do not remove front matter. +_comment: Do not remove front matter. --- Hugo uses Go's [text/template] and [html/template] packages. diff --git a/docs/content/en/functions/_common/locales.md b/docs/content/en/functions/_common/locales.md index fd8415781..42d008776 100644 --- a/docs/content/en/functions/_common/locales.md +++ b/docs/content/en/functions/_common/locales.md @@ -1,5 +1,5 @@ --- -# Do not remove front matter. +_comment: Do not remove front matter. --- {{% note %}} diff --git a/docs/content/en/functions/_common/regular-expressions.md b/docs/content/en/functions/_common/regular-expressions.md index 48e020ac6..58f81a2ee 100644 --- a/docs/content/en/functions/_common/regular-expressions.md +++ b/docs/content/en/functions/_common/regular-expressions.md @@ -1,5 +1,5 @@ --- -# Do not remove front matter. +_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. diff --git a/docs/content/en/functions/_common/time-layout-string.md b/docs/content/en/functions/_common/time-layout-string.md index 827dc9894..3664eaef2 100644 --- a/docs/content/en/functions/_common/time-layout-string.md +++ b/docs/content/en/functions/_common/time-layout-string.md @@ -1,5 +1,5 @@ --- -# Do not remove front matter. +_comment: Do not remove front matter. --- Format a `time.Time` value based on [Go's reference time]: diff --git a/docs/content/en/functions/css/PostCSS.md b/docs/content/en/functions/css/PostCSS.md index 750971c10..8d4143575 100644 --- a/docs/content/en/functions/css/PostCSS.md +++ b/docs/content/en/functions/css/PostCSS.md @@ -124,6 +124,6 @@ module.exports = { ``` [node.js]: https://nodejs.org/en/download -[postcss plugins]: https://www.postcss.parts/ +[postcss plugins]: https://postcss.org/docs/postcss-plugins [supported file name]: https://github.com/postcss/postcss-load-config#usage [transpile to CSS]: /functions/css/sass/ diff --git a/docs/content/en/functions/fmt/_common/fmt-layout.md b/docs/content/en/functions/fmt/_common/fmt-layout.md index ff69ce5e4..09a9ee867 100644 --- a/docs/content/en/functions/fmt/_common/fmt-layout.md +++ b/docs/content/en/functions/fmt/_common/fmt-layout.md @@ -1,5 +1,5 @@ --- -# Do not remove front matter. +_comment: Do not remove front matter. --- The documentation for Go's [fmt] package describes the structure and content of the format string. diff --git a/docs/content/en/functions/go-template/_common/text-template.md b/docs/content/en/functions/go-template/_common/text-template.md index 71718c3fd..4b934c1e9 100644 --- a/docs/content/en/functions/go-template/_common/text-template.md +++ b/docs/content/en/functions/go-template/_common/text-template.md @@ -1,5 +1,5 @@ --- -# Do not remove front matter. +_comment: Do not remove front matter. --- See Go's [text/template] documentation for more information. diff --git a/docs/content/en/functions/go-template/_common/truthy-falsy.md b/docs/content/en/functions/go-template/_common/truthy-falsy.md index c41bb6561..e15e58d61 100644 --- a/docs/content/en/functions/go-template/_common/truthy-falsy.md +++ b/docs/content/en/functions/go-template/_common/truthy-falsy.md @@ -1,5 +1,5 @@ --- -# Do not remove front matter. +_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. diff --git a/docs/content/en/functions/hugo/Store.md b/docs/content/en/functions/hugo/Store.md new file mode 100644 index 000000000..b0503a5ff --- /dev/null +++ b/docs/content/en/functions/hugo/Store.md @@ -0,0 +1,125 @@ +--- +title: hugo.Store +description: Returns a global, persistent "scratch pad" to store and manipulate data. +categories: [] +keywords: [] +action: + related: + - methods/page/store + - methods/site/store + - functions/collections/NewScratch + returnType: maps.Scratch + signatures: [hugo.Store] +toc: true +--- + +{{< new-in 0.139.0 >}} + +The global `hugo.Store` function creates a persistent [scratch pad] to store and manipulate data. To create a locally scoped, use the [`newScratch`] function. + +[`Scratch`]: /functions/hugo/scratch/ +[`newScratch`]: /functions/collections/newscratch/ +[scratch pad]: /getting-started/glossary/#scratch-pad + +## Methods + +###### Set + +Sets the value of a given key. + +```go-html-template +{{ hugo.Store.Set "greeting" "Hello" }} +``` + +###### Get + +Gets the value of a given key. + +```go-html-template +{{ hugo.Store.Set "greeting" "Hello" }} +{{ hugo.Store.Get "greeting" }} → Hello +``` + +###### Add + +Adds a given value to existing value(s) of the given key. + +For single values, `Add` accepts values that support Go's `+` operator. If the first `Add` for a key is an array or slice, the following adds will be appended to that list. + +```go-html-template +{{ hugo.Store.Set "greeting" "Hello" }} +{{ hugo.Store.Add "greeting" "Welcome" }} +{{ hugo.Store.Get "greeting" }} → HelloWelcome +``` + +```go-html-template +{{ hugo.Store.Set "total" 3 }} +{{ hugo.Store.Add "total" 7 }} +{{ hugo.Store.Get "total" }} → 10 +``` + +```go-html-template +{{ hugo.Store.Set "greetings" (slice "Hello") }} +{{ hugo.Store.Add "greetings" (slice "Welcome" "Cheers") }} +{{ hugo.Store.Get "greetings" }} → [Hello Welcome Cheers] +``` + +###### SetInMap + +Takes a `key`, `mapKey` and `value` and adds a map of `mapKey` and `value` to the given `key`. + +```go-html-template +{{ hugo.Store.SetInMap "greetings" "english" "Hello" }} +{{ hugo.Store.SetInMap "greetings" "french" "Bonjour" }} +{{ hugo.Store.Get "greetings" }} → map[english:Hello french:Bonjour] +``` + +###### DeleteInMap + +Takes a `key` and `mapKey` and removes the map of `mapKey` from the given `key`. + +```go-html-template +{{ hugo.Store.SetInMap "greetings" "english" "Hello" }} +{{ hugo.Store.SetInMap "greetings" "french" "Bonjour" }} +{{ hugo.Store.DeleteInMap "greetings" "english" }} +{{ hugo.Store.Get "greetings" }} → map[french:Bonjour] +``` + +###### GetSortedMapValues + +Returns an array of values from `key` sorted by `mapKey`. + +```go-html-template +{{ hugo.Store.SetInMap "greetings" "english" "Hello" }} +{{ hugo.Store.SetInMap "greetings" "french" "Bonjour" }} +{{ hugo.Store.GetSortedMapValues "greetings" }} → [Hello Bonjour] +``` + +###### Delete + +Removes the given key. + +```go-html-template +{{ hugo.Store.Set "greeting" "Hello" }} +{{ hugo.Store.Delete "greeting" }} +``` + +## Determinate values + +The `Store` method is often used to set scratch pad values within a shortcode, a partial template called by a shortcode, or by a Markdown render hook. In all three cases, the scratch pad values are indeterminate until Hugo renders the page content. + +If you need to access a scratch pad value from a parent template, and the parent template has not yet rendered the page content, you can trigger content rendering by assigning the returned value to a [noop] variable: + +[noop]: /getting-started/glossary/#noop + +```go-html-template +{{ $noop := .Content }} +{{ hugo.Store.Get "mykey" }} +``` + +You can also trigger content rendering with the `ContentWithoutSummary`, `FuzzyWordCount`, `Len`, `Plain`, `PlainWords`, `ReadingTime`, `Summary`, `Truncated`, and `WordCount` methods. For example: + +```go-html-template +{{ $noop := .WordCount }} +{{ hugo.Store.Get "mykey" }} +``` diff --git a/docs/content/en/functions/images/_common/apply-image-filter.md b/docs/content/en/functions/images/_common/apply-image-filter.md index 15eddb485..08e08238f 100644 --- a/docs/content/en/functions/images/_common/apply-image-filter.md +++ b/docs/content/en/functions/images/_common/apply-image-filter.md @@ -1,5 +1,5 @@ --- -# Do not remove front matter. +_comment: Do not remove front matter. --- Apply the filter using the [`images.Filter`] function: diff --git a/docs/content/en/functions/resources/_common/postcss-windows-warning.md b/docs/content/en/functions/resources/_common/postcss-windows-warning.md index 1b72e74db..e2d97850b 100644 --- a/docs/content/en/functions/resources/_common/postcss-windows-warning.md +++ b/docs/content/en/functions/resources/_common/postcss-windows-warning.md @@ -1,5 +1,5 @@ --- -# Do not remove front matter. +_comment: Do not remove front matter. --- 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]. diff --git a/docs/content/en/functions/time/_common/parsable-date-time-strings.md b/docs/content/en/functions/time/_common/parsable-date-time-strings.md index 6d1633a6f..92842767e 100644 --- a/docs/content/en/functions/time/_common/parsable-date-time-strings.md +++ b/docs/content/en/functions/time/_common/parsable-date-time-strings.md @@ -1,5 +1,5 @@ --- -# Do not remove front matter. +_comment: Do not remove front matter. --- Format|Time zone diff --git a/docs/content/en/functions/transform/Unmarshal.md b/docs/content/en/functions/transform/Unmarshal.md index 998152eb2..960332c44 100644 --- a/docs/content/en/functions/transform/Unmarshal.md +++ b/docs/content/en/functions/transform/Unmarshal.md @@ -230,7 +230,7 @@ Let's add a `lang` attribute to the `title` nodes of our RSS feed, and a namespa <language>en-US</language> <atom:link href="https://example.org/books/index.xml" rel="self" type="application/rss+xml" /> <item> - <title lang="fr">The Hunchback of Notre Dame</title> + <title lang="en">The Hunchback of Notre Dame</title> <description>Written by Victor Hugo</description> <isbn:number>9780140443530</isbn:number> <link>https://example.org/books/the-hunchback-of-notre-dame/</link> @@ -238,7 +238,7 @@ Let's add a `lang` attribute to the `title` nodes of our RSS feed, and a namespa <guid>https://example.org/books/the-hunchback-of-notre-dame/</guid> </item> <item> - <title lang="en">Les Misérables</title> + <title lang="fr">Les Misérables</title> <description>Written by Victor Hugo</description> <isbn:number>9780451419439</isbn:number> <link>https://example.org/books/les-miserables/</link> @@ -266,7 +266,7 @@ Each item node looks like this: "pubDate": "Mon, 09 Oct 2023 09:27:12 -0700", "title": { "#text": "The Hunchback of Notre Dame", - "-lang": "fr" + "-lang": "en" } } ``` @@ -290,8 +290,8 @@ Hugo renders this to: ```html <ul> - <li>The Hunchback of Notre Dame (fr) 9780140443530</li> - <li>Les Misérables (en) 9780451419439</li> + <li>The Hunchback of Notre Dame (en) 9780140443530</li> + <li>Les Misérables (fr) 9780451419439</li> </ul> ``` diff --git a/docs/content/en/functions/urls/Anchorize.md b/docs/content/en/functions/urls/Anchorize.md index f3939675a..d8866ae05 100644 --- a/docs/content/en/functions/urls/Anchorize.md +++ b/docs/content/en/functions/urls/Anchorize.md @@ -28,10 +28,10 @@ This controls the behavior of the `anchorize` function and the generation of hea Set `autoHeadingIDType` to one of: github -: Compatible with GitHub. This is the default, and strongly recommended. +: Compatible with GitHub. This is the default. github-ascii -: Similar to the "github" setting, but removes non-ASCII characters. +: Similar to the `github` setting, but removes non-ASCII characters. blackfriday : Provided for backwards compatibility with Hugo v0.59.1 and earlier. This option will be removed in a future release. diff --git a/docs/content/en/functions/urls/_common/anchorize-vs-urlize.md b/docs/content/en/functions/urls/_common/anchorize-vs-urlize.md index 718c14098..710a3c592 100644 --- a/docs/content/en/functions/urls/_common/anchorize-vs-urlize.md +++ b/docs/content/en/functions/urls/_common/anchorize-vs-urlize.md @@ -1,5 +1,5 @@ --- -# Do not remove front matter. +_comment: Do not remove front matter. --- The [`anchorize`] and [`urlize`] functions are similar: |