Skip to content

Commit 575d603

Browse files
jmooringbep
authored andcommitted
Update docs for v0.141.0
Closes #2808
1 parent a0a442d commit 575d603

File tree

30 files changed

+787
-932
lines changed

30 files changed

+787
-932
lines changed

assets/images/examples/mask.png

134 KB
Loading

content/en/about/privacy.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ respectDoNotTrack = false
3939
[privacy.instagram]
4040
disable = false
4141
simple = false
42-
[privacy.twitter]
42+
[privacy.vimeo]
4343
disable = false
4444
enableDNT = false
4545
simple = false
46-
[privacy.vimeo]
46+
[privacy.x]
4747
disable = false
4848
enableDNT = false
4949
simple = false
@@ -64,10 +64,10 @@ disable = true
6464
disable = true
6565
[privacy.instagram]
6666
disable = true
67-
[privacy.twitter]
68-
disable = true
6967
[privacy.vimeo]
7068
disable = true
69+
[privacy.x]
70+
disable = true
7171
[privacy.youtube]
7272
disable = true
7373
{{< /code-toggle >}}
@@ -92,19 +92,19 @@ simple
9292
disableInlineCSS = true
9393
{{< /code-toggle >}}
9494

95-
### Twitter
95+
### X
9696

9797
enableDNT
98-
: Enabling this for the twitter/tweet shortcode, the tweet and its embedded page on your site are not used for purposes that include personalized suggestions and personalized ads.
98+
: Enabling this for the x shortcode, the post and its embedded page on your site are not used for purposes that include personalized suggestions and personalized ads.
9999

100100
simple
101-
: If simple mode is enabled, a static and no-JS version of a tweet will be built.
101+
: If simple mode is enabled, a static and no-JS version of a post will be built.
102102

103-
**Note:** If you use the _simple mode_ for Twitter, you may want to disable the inline styles provided by Hugo:
103+
**Note:** If you use the _simple mode_ for X, you may want to disable the inline styles provided by Hugo:
104104

105105
{{< code-toggle file=hugo >}}
106106
[services]
107-
[services.twitter]
107+
[services.x]
108108
disableInlineCSS = true
109109
{{< /code-toggle >}}
110110

content/en/commands/hugo.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ hugo [flags]
7272
* [hugo completion](/commands/hugo_completion/) - Generate the autocompletion script for the specified shell
7373
* [hugo config](/commands/hugo_config/) - Display site configuration
7474
* [hugo convert](/commands/hugo_convert/) - Convert front matter to another format
75-
* [hugo deploy](/commands/hugo_deploy/) - Deploy your site to a cloud provider
7675
* [hugo env](/commands/hugo_env/) - Display version and environment info
7776
* [hugo gen](/commands/hugo_gen/) - Generate documentation and syntax highlighting styles
7877
* [hugo import](/commands/hugo_import/) - Import a site from another system

content/en/content-management/content-adapters.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,14 @@ Step 3
193193
{{/* Get remote data. */}}
194194
{{ $data := dict }}
195195
{{ $url := "https://gohugo.io/shared/examples/data/books.json" }}
196-
{{ with resources.GetRemote $url }}
196+
{{ with try (resources.GetRemote $url) }}
197197
{{ with .Err }}
198198
{{ errorf "Unable to get remote resource %s: %s" $url . }}
199-
{{ else }}
199+
{{ else with .Value }}
200200
{{ $data = . | transform.Unmarshal }}
201+
{{ else }}
202+
{{ errorf "Unable to get remote resource %s" $url }}
201203
{{ end }}
202-
{{ else }}
203-
{{ errorf "Unable to get remote resource %s" $url }}
204204
{{ end }}
205205

206206
{{/* Add pages and page resources. */}}
@@ -223,10 +223,10 @@ Step 3
223223
{{/* Add page resource. */}}
224224
{{ $item := . }}
225225
{{ with $url := $item.cover }}
226-
{{ with resources.GetRemote $url }}
226+
{{ with try (resources.GetRemote $url) }}
227227
{{ with .Err }}
228228
{{ errorf "Unable to get remote resource %s: %s" $url . }}
229-
{{ else }}
229+
{{ else with .Value }}
230230
{{ $content := dict "mediaType" .MediaType.Type "value" .Content }}
231231
{{ $params := dict "alt" $item.title }}
232232
{{ $resource := dict
@@ -235,9 +235,9 @@ Step 3
235235
"path" (printf "%s/cover.%s" $item.title .MediaType.SubType)
236236
}}
237237
{{ $.AddResource $resource }}
238+
{{ else }}
239+
{{ errorf "Unable to get remote resource %s" $url }}
238240
{{ end }}
239-
{{ else }}
240-
{{ errorf "Unable to get remote resource %s" $url }}
241241
{{ end }}
242242
{{ end }}
243243

content/en/content-management/image-processing/index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ Example 3: A more concise way to skip image rendering if the resource is not fou
8888
Example 4: Skips rendering if there's problem accessing a remote resource.
8989

9090
```go-html-template
91-
{{ $u := "https://gohugo.io/img/hugo-logo.png" }}
92-
{{ with resources.GetRemote $u }}
91+
{{ $url := "https://gohugo.io/img/hugo-logo.png" }}
92+
{{ with try (resources.GetRemote $url) }}
9393
{{ with .Err }}
9494
{{ errorf "%s" . }}
95-
{{ else }}
95+
{{ else with .Value }}
9696
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}">
97+
{{ else }}
98+
{{ errorf "Unable to get remote resource %q" $url }}
9799
{{ end }}
98-
{{ else }}
99-
{{ errorf "Unable to get remote resource %q" $u }}
100100
{{ end }}
101101
```
102102

content/en/content-management/related.md

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -157,22 +157,3 @@ pattern
157157

158158
toLower
159159
: (`bool`) See above.
160-
161-
## Performance considerations
162-
163-
**Fast is Hugo's middle name** and we would not have released this feature had it not been blistering fast.
164-
165-
This feature has been in the back log and requested by many for a long time. The development got this recent kick start from this Twitter thread:
166-
167-
{{< tweet user="scott_lowe" id="898398437527363585" >}}
168-
169-
Scott S. Lowe removed the "Related Content" section built using the `intersect` template function on tags, and the build time dropped from 30 seconds to less than 2 seconds on his 1700 content page sized blog.
170-
171-
He should now be able to add an improved version of that "Related Content" section without giving up the fast live-reloads. But it's worth noting that:
172-
173-
* If you don't use any of the `Related` methods, you will not use the Relate Content feature, and performance will be the same as before.
174-
* Calling `.RegularPages.Related` etc. will create one inverted index, also sometimes named posting list, that will be reused for any lookups in that same page collection. Doing that in addition to, as an example, calling `.Pages.Related` will work as expected, but will create one additional inverted index. This should still be very fast, but worth having in mind, especially for bigger sites.
175-
176-
{{% note %}}
177-
We currently do not index **Page content**. We thought we would release something that will make most people happy before we start solving [Sherlock's last case](https://github.com/joearms/sherlock).
178-
{{% /note %}}

content/en/content-management/shortcodes.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,6 @@ Rendered:
498498
{{% note %}}
499499
To override Hugo's embedded `twitter` shortcode, copy the [source code] to a file with the same name in the layouts/shortcodes directory.
500500

501-
You may call the `twitter` shortcode by using its `tweet` alias.
502-
503501
[source code]: {{% eturl twitter %}}
504502
{{% /note %}}
505503

content/en/functions/data/GetCSV.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,16 @@ Consider using the [`resources.GetRemote`] function with [`transform.Unmarshal`]
134134

135135
```go-html-template
136136
{{ $data := dict }}
137-
{{ $u := "https://example.org/pets.csv" }}
138-
{{ with resources.GetRemote $u }}
137+
{{ $url := "https://example.org/pets.csv" }}
138+
{{ with try (resources.GetRemote $url) }}
139139
{{ with .Err }}
140140
{{ errorf "%s" . }}
141-
{{ else }}
141+
{{ else with .Value }}
142142
{{ $opts := dict "delimiter" "," }}
143143
{{ $data = . | transform.Unmarshal $opts }}
144+
{{ else }}
145+
{{ errorf "Unable to get remote resource %q" $url }}
144146
{{ end }}
145-
{{ else }}
146-
{{ errorf "Unable to get remote resource %q" $u }}
147147
{{ end }}
148148
```
149149

content/en/functions/data/GetJSON.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,15 @@ Consider using the [`resources.GetRemote`] function with [`transform.Unmarshal`]
137137

138138
```go-html-template
139139
{{ $data := dict }}
140-
{{ $u := "https://example.org/books.json" }}
141-
{{ with resources.GetRemote $u }}
140+
{{ $url := "https://example.org/books.json" }}
141+
{{ with try (resources.GetRemote $url) }}
142142
{{ with .Err }}
143143
{{ errorf "%s" . }}
144-
{{ else }}
144+
{{ else with .Value }}
145145
{{ $data = . | transform.Unmarshal }}
146+
{{ else }}
147+
{{ errorf "Unable to get remote resource %q" $url }}
146148
{{ end }}
147-
{{ else }}
148-
{{ errorf "Unable to get remote resource %q" $u }}
149149
{{ end }}
150150
```
151151

content/en/functions/encoding/Base64Decode.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ https://api.github.com/repos/gohugoio/hugo/readme
2525
To retrieve and render the content:
2626

2727
```go-html-template
28-
{{ $u := "https://api.github.com/repos/gohugoio/hugo/readme" }}
29-
{{ with resources.GetRemote $u }}
28+
{{ $url := "https://api.github.com/repos/gohugoio/hugo/readme" }}
29+
{{ with try (resources.GetRemote $url) }}
3030
{{ with .Err }}
3131
{{ errorf "%s" . }}
32-
{{ else }}
32+
{{ else with .Value}}
3333
{{ with . | transform.Unmarshal }}
3434
{{ .content | base64Decode | markdownify }}
3535
{{ end }}
36+
{{ else }}
37+
{{ errorf "Unable to get remote resource %q" $url }}
3638
{{ end }}
37-
{{ else }}
38-
{{ errorf "Unable to get remote resource %q" $u }}
3939
{{ end }}
4040
```

content/en/functions/go-template/return.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ action:
1313
toc: true
1414
---
1515

16-
The `return` statement is a custom addition to Go's [text/template] package. Used within partial templates, the `return` statement terminates template execution and returns the given value, if any.
16+
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.
1717

1818
The returned value may be of any data type including, but not limited to, [`bool`], [`float`], [`int`], [`map`], [`resource`], [`slice`], and [`string`].
1919

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
---
2+
title: try
3+
description: Returns a TryValue object after evaluating the given expression.
4+
categories: []
5+
keywords: []
6+
action:
7+
aliases: []
8+
related: []
9+
returnType: TryValue
10+
signatures: ['try EXPRESSION']
11+
toc: true
12+
---
13+
14+
{{< new-in 0.141.0 >}}
15+
16+
The `try` statement is a non-standard extension to Go's [text/template] package. It introduces a mechanism for handling errors within templates, mimicking the `try-catch` constructs found in other programming languages.
17+
18+
[text/template]: https://pkg.go.dev/text/template
19+
20+
## Methods
21+
22+
The `TryValue` object encapsulates the result of evaluating the expression, and provides two methods:
23+
24+
Err
25+
: (`string`) Returns a string representation of the error thrown by the expression, if an error occurred, or returns `nil` if the expression evaluated without errors.
26+
27+
Value
28+
: (`any`) Returns the result of the expression if the evaluation was successful, or returns `nil` if an error occurred while evaluating the expression.
29+
30+
## Explanation
31+
32+
By way of example, let's divide a number by zero:
33+
34+
```go-html-template
35+
{{ $x := 1 }}
36+
{{ $y := 0 }}
37+
{{ $result := div $x $y }}
38+
{{ printf "%v divided by %v equals %v" $x $y .Value }}
39+
```
40+
41+
As expected, the example above throws an error and fails the build:
42+
43+
```terminfo
44+
Error: error calling div: can't divide the value by 0
45+
```
46+
47+
Instead of failing the build, we can catch the error and emit a warning:
48+
49+
```go-html-template
50+
{{ $x := 1 }}
51+
{{ $y := 0 }}
52+
{{ with try (div $x $y) }}
53+
{{ with .Err }}
54+
{{ warnf "%s" . }}
55+
{{ else }}
56+
{{ printf "%v divided by %v equals %v" $x $y .Value }}
57+
{{ end }}
58+
{{ end }}
59+
```
60+
61+
The error thrown by the expression is logged to the console as a warning:
62+
63+
```terminfo
64+
WARN error calling div: can't divide the value by 0
65+
```
66+
67+
Now let's change the arguments to avoid dividing by zero:
68+
69+
```go-html-template
70+
{{ $x := 42 }}
71+
{{ $y := 6 }}
72+
{{ with try (div $x $y) }}
73+
{{ with .Err }}
74+
{{ warnf "%s" . }}
75+
{{ else }}
76+
{{ printf "%v divided by %v equals %v" $x $y .Value }}
77+
{{ end }}
78+
{{ end }}
79+
```
80+
81+
Hugo renders the above to:
82+
83+
```html
84+
42 divided by 6 equals 7
85+
```
86+
87+
## Example
88+
89+
Error handling is essential when using the [`resources.GetRemote`] function to capture remote resources such as data or images. When calling this function, if the HTTP request fails, Hugo will fail the build.
90+
91+
[`resources.GetRemote`]: /functions/resources/getremote/
92+
93+
Instead of failing the build, we can catch the error and emit a warning:
94+
95+
```go-html-template
96+
{{ $url := "https://broken-example.org/images/a.jpg" }}
97+
{{ with try (resources.GetRemote $url) }}
98+
{{ with .Err }}
99+
{{ warnf "%s" . }}
100+
{{ else with .Value }}
101+
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
102+
{{ else }}
103+
{{ errorf "Unable to get remote resource %q" $url }}
104+
{{ end }}
105+
{{ end }}
106+
```
107+
108+
{{% note %}}
109+
Hugo does not classify an HTTP response with status code 404 as an error. In this case `resources.GetRemote` returns nil.
110+
{{% /note %}}

content/en/functions/images/Mask.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
title: images.Mask
3+
description: Returns an image filter that applies a mask to the source image.
4+
categories: []
5+
keywords: []
6+
action:
7+
aliases: []
8+
related:
9+
- functions/images/Filter
10+
- methods/resource/Filter
11+
returnType: images.filter
12+
signatures: [images.Mask RESOURCE]
13+
toc: true
14+
---
15+
16+
{{< new-in 0.141.0 >}}
17+
18+
The `images.Mask` filter applies a mask to an image. Black pixels in the mask make the corresponding areas of the base image transparent, while white pixels keep them opaque. Color images are converted to grayscale for masking purposes. The mask is automatically resized to match the dimensions of the base image.
19+
20+
## Usage
21+
22+
Create the filter:
23+
24+
```go-html-template
25+
{{ $filter := images.Mak "images/mask.png" }}
26+
```
27+
28+
{{% include "functions/images/_common/apply-image-filter.md" %}}
29+
30+
## Example
31+
32+
Mask
33+
34+
{{< img
35+
src="images/examples/mask.png"
36+
example=false
37+
>}}
38+
39+
{{< img
40+
src="images/examples/zion-national-park.jpg"
41+
alt="Zion National Park"
42+
filter="mask"
43+
filterArgs="images/examples/mask.png"
44+
example=true
45+
>}}

0 commit comments

Comments
 (0)