Skip to content

Commit

Permalink
Merge commit '7c62d6ef1654c0383eae474d3bd9ddf7754c1f30'
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Aug 7, 2023
2 parents 641390f + 7c62d6e commit 5d5fb22
Show file tree
Hide file tree
Showing 43 changed files with 253 additions and 319 deletions.
4 changes: 0 additions & 4 deletions docs/config/_default/security.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@

enableInlineShortcodes = false

[exec]
allow = ['^go$']
osEnv = ['^PATH$']

[funcs]
getenv = ['^HUGO_', '^REPOSITORY_URL$', '^BRANCH$']

Expand Down
2 changes: 1 addition & 1 deletion docs/content/en/content-management/multilingual.md
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ See [lang.FormatNumber] and [lang.FormatNumberCustom] for details.
With this template code:

```go-html-template
{{ 512.5032 | lang.FormatPercent 2 }} ---> 512.50%
{{ 512.5032 | lang.FormatPercent 2 }} 512.50%
```

The rendered page displays:
Expand Down
18 changes: 9 additions & 9 deletions docs/content/en/content-management/summaries.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,19 @@ You can show content summaries with the following code. You could use the follow

{{< code file="page-list-with-summaries.html" >}}
{{ range first 10 .Pages }}
<article>
<!-- this <div> includes the title summary -->
<div>
<h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
{{ .Summary }}
</div>
{{ if .Truncated }}
<article>
<!-- this <div> includes the title summary -->
<div>
<h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
{{ .Summary }}
</div>
{{ if .Truncated }}
<!-- This <div> includes a read more link, but only if the summary is truncated... -->
<div>
<a href="{{ .RelPermalink }}">Read More…</a>
</div>
{{ end }}
</article>
{{ end }}
</article>
{{ end }}
{{< /code >}}

Expand Down
12 changes: 6 additions & 6 deletions docs/content/en/content-management/toc.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ The following is an example of a very basic [single page template]:

{{< code file="layout/_default/single.html" >}}
{{ define "main" }}
<main>
<main>
<article>
<header>
<header>
<h1>{{ .Title }}</h1>
</header>
{{ .Content }}
</header>
{{ .Content }}
</article>
<aside>
{{ .TableOfContents }}
{{ .TableOfContents }}
</aside>
</main>
</main>
{{ end }}
{{< /code >}}

Expand Down
14 changes: 7 additions & 7 deletions docs/content/en/functions/adddate.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ relatedfuncs: [now]
```go-html-template
{{ $d := "2022-01-01" | time.AsTime }}
{{ $d.AddDate 0 0 1 | time.Format "2006-01-02" }} --> 2022-01-02
{{ $d.AddDate 0 1 1 | time.Format "2006-01-02" }} --> 2022-02-02
{{ $d.AddDate 1 1 1 | time.Format "2006-01-02" }} --> 2023-02-02
{{ $d.AddDate 0 0 1 | time.Format "2006-01-02" }} 2022-01-02
{{ $d.AddDate 0 1 1 | time.Format "2006-01-02" }} 2022-02-02
{{ $d.AddDate 1 1 1 | time.Format "2006-01-02" }} 2023-02-02
{{ $d.AddDate -1 -1 -1 | time.Format "2006-01-02" }} --> 2020-11-30
{{ $d.AddDate -1 -1 -1 | time.Format "2006-01-02" }} 2020-11-30
```

{{% note %}}
Expand All @@ -28,11 +28,11 @@ See [this explanation](https://github.com/golang/go/issues/31145#issuecomment-47

```go-html-template
{{ $d := "2023-01-31" | time.AsTime }}
{{ $d.AddDate 0 1 0 | time.Format "2006-01-02" }} --> 2023-03-03
{{ $d.AddDate 0 1 0 | time.Format "2006-01-02" }} 2023-03-03
{{ $d := "2024-01-31" | time.AsTime }}
{{ $d.AddDate 0 1 0 | time.Format "2006-01-02" }} --> 2024-03-02
{{ $d.AddDate 0 1 0 | time.Format "2006-01-02" }} 2024-03-02
{{ $d := "2024-02-29" | time.AsTime }}
{{ $d.AddDate 1 0 0 | time.Format "2006-01-02" }} --> 2025-03-01
{{ $d.AddDate 1 0 0 | time.Format "2006-01-02" }} 2025-03-01
```
2 changes: 1 addition & 1 deletion docs/content/en/functions/after.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ You can use `after` in combination with the [`first` function] and Hugo's [power
<h2>Featured Article</h2>
{{ range first 1 .Pages.ByPublishDate.Reverse }}
<header>
<h3><a href="{{ . Permalink }}">{{ .Title }}</a></h3>
<h3><a href="{{ .Permalink }}">{{ .Title }}</a></h3>
</header>
<p>{{ .Description }}</p>
{{ end }}
Expand Down
12 changes: 6 additions & 6 deletions docs/content/en/functions/anchorize.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ If [Goldmark](/getting-started/configuration-markup#goldmark) is set as `default
Since the `defaultMarkdownHandler` and this template function use the same sanitizing logic, you can use the latter to determine the ID of a header for linking with anchor tags.

```go-html-template
{{ anchorize "This is a header" }} --> "this-is-a-header"
{{ anchorize "This is also a header" }} --> "this-is-also----a-header"
{{ anchorize "main.go" }} --> "maingo"
{{ anchorize "Article 123" }} --> "article-123"
{{ anchorize "<- Let's try this, shall we?" }} --> "--lets-try-this-shall-we"
{{ anchorize "Hello, 世界" }} --> "hello-世界"
{{ anchorize "This is a header" }} "this-is-a-header"
{{ anchorize "This is also a header" }} "this-is-also----a-header"
{{ anchorize "main.go" }} "maingo"
{{ anchorize "Article 123" }} "article-123"
{{ anchorize "<- Let's try this, shall we?" }} "--lets-try-this-shall-we"
{{ anchorize "Hello, 世界" }} "hello-世界"
```
8 changes: 8 additions & 0 deletions docs/content/en/functions/append.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,12 @@ The same example appending a slice to a slice:
{{ $s = $s | append (slice "d" "e") }}
```

If a slice contains other slices, further slices will be appended as values:

```go-html-template
{{ $s := slice (slice "a" "b") (slice "c" "d") }}
{{ $s = $s | append (slice "e" "f") (slice "g" "h") }}
{{/* $s now contains a [][]string containing four slices: ["a" "b"], ["c" "d"], ["e" "f"], and ["g" "h"] */}}
```

The `append` function works for all types, including `Pages`.
3 changes: 3 additions & 0 deletions docs/content/en/functions/common/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
+++
headless = true
+++
8 changes: 8 additions & 0 deletions docs/content/en/functions/common/regular-expressions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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
14 changes: 7 additions & 7 deletions docs/content/en/functions/fileExists.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ content/
The function returns these values:

```go-html-template
{{ os.FileExists "content" }} --> true
{{ os.FileExists "content/news" }} --> true
{{ os.FileExists "content/news/article-1" }} --> false
{{ os.FileExists "content/news/article-1.md" }} --> true
{{ os.FileExists "news" }} --> true
{{ os.FileExists "news/article-1" }} --> false
{{ os.FileExists "news/article-1.md" }} --> true
{{ os.FileExists "content" }} true
{{ os.FileExists "content/news" }} true
{{ os.FileExists "content/news/article-1" }} false
{{ os.FileExists "content/news/article-1.md" }} true
{{ os.FileExists "news" }} true
{{ os.FileExists "news/article-1" }} false
{{ os.FileExists "news/article-1.md" }} true
```
16 changes: 1 addition & 15 deletions docs/content/en/functions/findRe.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,7 @@ relatedfuncs: [findRESubmatch, replaceRE]
---
By default, `findRE` finds all matches. You can limit the number of matches with an optional LIMIT parameter.

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.

[string literal]: https://go.dev/ref/spec#String_literals

This function uses the [RE2] regular expression library. See the [RE2 syntax documentation] for details. Note that the RE2 `\C` escape sequence is not supported.

[RE2]: https://github.com/google/re2/
[RE2 syntax documentation]: https://github.com/google/re2/wiki/Syntax/

{{% note %}}
The RE2 syntax is a subset of that accepted by [PCRE], roughly speaking, and with various [caveats].

[caveats]: https://swtch.com/~rsc/regexp/regexp3.html#caveats
[PCRE]: https://www.pcre.org/
{{% /note %}}
{{% readfile file="/functions/common/regular-expressions.md" %}}

This example returns a slice of all second level headings (`h2` elements) within the rendered `.Content`:

Expand Down
16 changes: 1 addition & 15 deletions docs/content/en/functions/findresubmatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,7 @@ relatedfuncs: [findRE, replaceRE]

By default, `findRESubmatch` finds all matches. You can limit the number of matches with an optional LIMIT parameter. A return value of nil indicates no match.

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.

[string literal]: https://go.dev/ref/spec#String_literals

This function uses the [RE2] regular expression library. See the [RE2 syntax documentation] for details. Note that the RE2 `\C` escape sequence is not supported.

[RE2]: https://github.com/google/re2/
[RE2 syntax documentation]: https://github.com/google/re2/wiki/Syntax/

{{% note %}}
The RE2 syntax is a subset of that accepted by [PCRE], roughly speaking, and with various [caveats].

[caveats]: https://swtch.com/~rsc/regexp/regexp3.html#caveats
[PCRE]: https://www.pcre.org/
{{% /note %}}
{{% readfile file="/functions/common/regular-expressions.md" %}}

## Demonstrative examples

Expand Down
8 changes: 4 additions & 4 deletions docs/content/en/functions/getenv.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ relatedfuncs: []
Examples:

```go-html-template
{{ os.Getenv "HOME" }} --> /home/victor
{{ os.Getenv "USER" }} --> victor
{{ os.Getenv "HOME" }} /home/victor
{{ os.Getenv "USER" }} victor
```

You can pass values when building your site:
Expand All @@ -31,8 +31,8 @@ hugo
And then retrieve the values within a template:

```go-html-template
{{ os.Getenv "MY_VAR1" }} --> foo
{{ os.Getenv "MY_VAR2" }} --> bar
{{ os.Getenv "MY_VAR1" }} foo
{{ os.Getenv "MY_VAR2" }} bar
```

With Hugo v0.91.0 and later, you must explicitly allow access to environment variables. For details, review [Hugo's Security Policy](/about/security-model/#security-policy). By default, environment variables beginning with `HUGO_` are allowed when using the `os.Getenv` function.
20 changes: 0 additions & 20 deletions docs/content/en/functions/hasPrefix.md

This file was deleted.

21 changes: 0 additions & 21 deletions docs/content/en/functions/hasSuffix.md

This file was deleted.

24 changes: 12 additions & 12 deletions docs/content/en/functions/merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,39 @@ Example 1
```go-html-template
{{ $merged := merge $m1 $m2 $m3 }}
{{ $merged.x }} --> baz
{{ $merged.y }} --> wobble
{{ $merged.z.a }} --> huey
{{ $merged.x }} baz
{{ $merged.y }} wobble
{{ $merged.z.a }} huey
```

Example 2

```go-html-template
{{ $merged := merge $m3 $m2 $m1 }}
{{ $merged.x }} --> foo
{{ $merged.y }} --> wibble
{{ $merged.z.a }} --> huey
{{ $merged.x }} foo
{{ $merged.y }} wibble
{{ $merged.z.a }} huey
```

Example 3

```go-html-template
{{ $merged := merge $m2 $m3 $m1 }}
{{ $merged.x }} --> foo
{{ $merged.y }} --> wobble
{{ $merged.z.a }} --> huey
{{ $merged.x }} foo
{{ $merged.y }} wobble
{{ $merged.z.a }} huey
```

Example 4

```go-html-template
{{ $merged := merge $m1 $m3 $m2 }}
{{ $merged.x }} --> bar
{{ $merged.y }} --> wibble
{{ $merged.z.a }} --> huey
{{ $merged.x }} bar
{{ $merged.y }} wibble
{{ $merged.z.a }} huey
```

{{% note %}}
Expand Down
10 changes: 5 additions & 5 deletions docs/content/en/functions/os.Stat.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ The `os.Stat` function attempts to resolve the path relative to the root of your

```go-html-template
{{ $f := os.Stat "README.md" }}
{{ $f.IsDir }} --> false (bool)
{{ $f.ModTime }} --> 2021-11-25 10:06:49.315429236 -0800 PST (time.Time)
{{ $f.Name }} --> README.md (string)
{{ $f.Size }} --> 241 (int64)
{{ $f.IsDir }} false (bool)
{{ $f.ModTime }} 2021-11-25 10:06:49.315429236 -0800 PST (time.Time)
{{ $f.Name }} README.md (string)
{{ $f.Size }} 241 (int64)
{{ $d := os.Stat "content" }}
{{ $d.IsDir }} --> true (bool)
{{ $d.IsDir }} true (bool)
```

Details of the `FileInfo` structure are available in the [Go documentation](https://pkg.go.dev/io/fs#FileInfo).
2 changes: 1 addition & 1 deletion docs/content/en/functions/readdir.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ This template code:

```go-html-template
{{ range os.ReadDir "content" }}
{{ .Name }} --> {{ .IsDir }}
{{ .Name }} {{ .IsDir }}
{{ end }}
```

Expand Down
16 changes: 1 addition & 15 deletions docs/content/en/functions/replacere.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,7 @@ relatedfuncs: [findRE, FindRESubmatch, replace]
---
By default, `replaceRE` replaces all matches. You can limit the number of matches with an optional LIMIT parameter.

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.

[string literal]: https://go.dev/ref/spec#String_literals

This function uses the [RE2] regular expression library. See the [RE2 syntax documentation] for details. Note that the RE2 `\C` escape sequence is not supported.

[RE2]: https://github.com/google/re2/
[RE2 syntax documentation]: https://github.com/google/re2/wiki/Syntax/

{{% note %}}
The RE2 syntax is a subset of that accepted by [PCRE], roughly speaking, and with various [caveats].

[caveats]: https://swtch.com/~rsc/regexp/regexp3.html#caveats
[PCRE]: https://www.pcre.org/
{{% /note %}}
{{% readfile file="/functions/common/regular-expressions.md" %}}

This example replaces two or more consecutive hyphens with a single hyphen:

Expand Down
2 changes: 1 addition & 1 deletion docs/content/en/functions/scratch.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Get the value of a given key.

Add 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.
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](/functions/append/) to that list.

```go-html-template
{{ $scratch.Add "greetings" "Hello" }}
Expand Down
Loading

0 comments on commit 5d5fb22

Please sign in to comment.