This commit is contained in:
Bjørn Erik Pedersen 2024-12-11 09:53:33 +01:00
commit b47376586a
No known key found for this signature in database
73 changed files with 705 additions and 163 deletions

View file

@ -1,5 +1,5 @@
---
# Do not remove front matter.
_comment: Do not remove front matter.
---
Path|Pattern|Match

View file

@ -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.

View file

@ -1,5 +1,5 @@
---
# Do not remove front matter.
_comment: Do not remove front matter.
---
{{% note %}}

View file

@ -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.

View file

@ -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]:

View file

@ -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/

View file

@ -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.

View file

@ -1,5 +1,5 @@
---
# Do not remove front matter.
_comment: Do not remove front matter.
---
See Go's [text/template] documentation for more information.

View file

@ -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.

View file

@ -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" }}
```

View file

@ -1,5 +1,5 @@
---
# Do not remove front matter.
_comment: Do not remove front matter.
---
Apply the filter using the [`images.Filter`] function:

View file

@ -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].

View file

@ -1,5 +1,5 @@
---
# Do not remove front matter.
_comment: Do not remove front matter.
---
Format|Time zone

View file

@ -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>
```

View file

@ -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.

View file

@ -1,5 +1,5 @@
---
# Do not remove front matter.
_comment: Do not remove front matter.
---
The [`anchorize`] and [`urlize`] functions are similar: