This commit is contained in:
Bjørn Erik Pedersen 2021-04-20 20:22:53 +02:00
commit 8f7891e70c
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F
64 changed files with 250 additions and 507 deletions

View file

@ -2,7 +2,6 @@
title: lang.NumFmt
description: "Formats a number with a given precision using the requested `negative`, `decimal`, and `grouping` options. The `options` parameter is a string consisting of `<negative> <decimal> <grouping>`."
godocref: ""
workson: []
date: 2017-02-01
publishdate: 2017-02-01
lastmod: 2017-08-21

View file

@ -25,14 +25,14 @@ The `AddDate` function takes three arguments in logical order of `years`, `month
Let's assume you have a file at `data/tweets.toml` that contains a list of Tweets to display on your site's homepage. The file is filled with `[[tweet]]` blocks; e.g.---
```
{{< code-toggle file="data/tweets" >}}
[[tweet]]
name = "Steve Francia"
twitter_handle = "@spf13"
quote = "I'm creator of Hugo. #metadocreference"
link = "https://twitter.com/spf13"
date = "2017-01-07T00:00:00Z"
```
{{< /code-toggle >}}
Let's assume you want to grab Tweets from the last two years and present them in a random order. In conjunction with the [`where`](/functions/where/) and [`now`](/functions/now/) functions, you can limit our range to the last two years via `now.AddDate -2 0 0`, which represents a point in time 2 years, 0 days, and 0 hours before the time of your last site build.

View file

@ -1,6 +1,6 @@
---
title: anchorize
description: Takes a string and sanitizes it the same way as Blackfriday does for markdown headers.
description: Takes a string and sanitizes it the same way as the [`defaultMarkdownHandler`](https://gohugo.io/getting-started/configuration-markup#configure-markup) does for markdown headers.
date: 2018-10-13
categories: [functions]
menu:
@ -13,8 +13,9 @@ workson: []
relatedfuncs: [humanize]
---
The template function uses the [`SanitizedAnchorName` logic from Blackfriday](https://github.com/russross/blackfriday#sanitized-anchor-names).
Since the same sanitizing logic is used as the markdown parser, you can determine the ID of a header for linking with anchor tags.
If [Goldmark](https://gohugo.io/getting-started/configuration-markup#goldmark) is set as `defaultMarkdownHandler`, the sanitizing logic adheres to the setting [`markup.goldmark.parser.autoHeadingIDType`](https://gohugo.io/getting-started/configuration-markup#goldmark). If [Blackfriday](https://gohugo.io/getting-started/configuration-markup#blackfriday) is set as `defaultMarkdownHandler`, this template function uses the [`SanitizedAnchorName` logic from Blackfriday](https://github.com/russross/blackfriday#sanitized-anchor-names) (the same applies when `markup.goldmark.parser.autoHeadingIDType` is set to `blackfriday`).
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.
```
{{anchorize "This is a header"}} → "this-is-a-header"

View file

@ -17,7 +17,7 @@ relatedfuncs: [Format,now,Unix,time]
deprecated: false
---
`dateFormat` converts the textual representation of the `datetime` into the specified format or returns it as a Go `time.Time` type value. These are formatted with the layout string.
`dateFormat` converts a timestamp string `INPUT` into the format specified by the `LAYOUT` string.
```
{{ dateFormat "Monday, Jan 2, 2006" "2015-01-21" }} → "Wednesday, Jan 21, 2015"
@ -27,5 +27,6 @@ deprecated: false
As of v0.19 of Hugo, the `dateFormat` function is *not* supported as part of Hugo's [multilingual feature](/content-management/multilingual/).
{{% /warning %}}
See the [`Format` function](/functions/format/) for a more complete list of date formatting options in your templates.
See [Gos Layout String](/functions/format/#gos-layout-string) to learn about how the `LAYOUT` string has to be formatted. There are also some useful examples.
See the [`time` function](/functions/time/) to convert a timestamp string to a Go `time.Time` type value.

View file

@ -2,7 +2,6 @@
title: delimit
description: Loops through any array, slice, or map and returns a string of all the values separated by a delimiter.
godocref:
workson: []
date: 2017-02-01
publishdate: 2017-02-01
lastmod: 2017-02-01

View file

@ -2,7 +2,6 @@
title: dict
description: Creates a dictionary from a list of key and value pairs.
godocref:
workson: []
date: 2017-02-01
publishdate: 2017-02-01
lastmod: 2017-02-26

View file

@ -52,13 +52,13 @@ Assume you want to add a `location = ""` field to your front matter for every ar
└── provo.toml
```
Here is an example of the data inside `data/locations/oslo.toml`:
Here is an example:
```
{{< code-toggle file="data/locations/oslo" >}}
website = "https://www.oslo.kommune.no"
pop_city = 658390
pop_metro = 1717900
```
{{< /code-toggle >}}
The example we will use will be an article on Oslo, whose front matter should be set to exactly the same name as the corresponding file name in `data/locations/`:

View file

@ -2,7 +2,6 @@
title: lang.Merge
description: "Merge missing translations from other languages."
godocref: ""
workson: []
date: 2018-03-16
categories: [functions]
keywords: [multilingual]

View file

@ -23,3 +23,8 @@ aliases: []
```
{{ .Title | markdownify }}
```
*Note*: if you need [Render Hooks][], which `markdownify` doesn't currently
support, use [.RenderString](/functions/renderstring/) instead.
[Render Hooks]: /getting-started/configuration-markup/#markdown-render-hooks

View file

@ -14,14 +14,14 @@ relatedfuncs: [dict, append, reflect.IsMap, reflect.IsSlice]
aliases: []
---
Merge creates a copy of the final `MAP` and merges any preceeding `MAP` into it in reverse order.
Merge creates a copy of the final `MAP` and merges any preceding `MAP` into it in reverse order.
Key handling is case-insensitive.
An example merging two maps.
```go-html-template
{{ $default_params := dict "color" "blue" "width" "50%" "height" "25%" }}
{{ $user_params := dict "color" "red" "extra" (dict "duration" 2) }}
{{ $default_params := dict "color" "blue" "width" "50%" "height" "25%" "icon" "star" }}
{{ $user_params := dict "color" "red" "icon" "mail" "extra" (dict "duration" 2) }}
{{ $params := merge $default_params $user_params }}
```
@ -39,5 +39,3 @@ Resulting __$params__:
{{% note %}}
Regardless of depth, merging only applies to maps. For slices, use [append]({{< ref "functions/append" >}})
{{% /note %}}

View file

@ -25,7 +25,7 @@ If there is no slash in `PATH`, it returns an empty directory and the base is se
**Note:** On Windows, `PATH` is converted to slash (`/`) separators.
```
{{ $dirFile := path.Split "a/news.html" }} → $dirDile.Dir → "a/", $dirFile.File → "news.html"
{{ $dirFile := path.Split "news.html" }} → $dirDile.Dir → "", $dirDile.File → "news.html"
{{ $dirFile := path.Split "a/b/c" }} → $dirDile.Dir → "a/b/", $dirDile.File → "c"
{{ $dirFile := path.Split "a/news.html" }} → $dirFile.Dir → "a/", $dirFile.File → "news.html"
{{ $dirFile := path.Split "news.html" }} → $dirFile.Dir → "", $dirFile.File → "news.html"
{{ $dirFile := path.Split "a/b/c" }} → $dirFile.Dir → "a/b/", $dirFile.File → "c"
```

View file

@ -22,9 +22,9 @@ It should not be used for HTML from a third-party, or HTML with unclosed tags or
Given a site-wide [`config.toml`][config] with the following `copyright` value:
```
{{< code-toggle file="config" >}}
copyright = "© 2015 Jane Doe. <a href=\"https://creativecommons.org/licenses/by/4.0/\">Some rights reserved</a>."
```
{{< /code-toggle >}}
`{{ .Site.Copyright | safeHTML }}` in a template would then output:

View file

@ -21,11 +21,11 @@ aliases: []
Example: Given a site-wide `config.toml` that contains this menu entry:
```
{{< code-toggle file="config" >}}
[[menu.main]]
name = "IRC: #golang at freenode"
url = "irc://irc.freenode.net/#golang"
```
{{< /code-toggle >}}
* <span class="bad">`<a href="{{ .URL }}">` &rarr; `<a href="#ZgotmplZ">`</span>
* <span class="good">`<a {{ printf "href=%q" .URL | safeHTMLAttr }}>` &rarr; `<a href="irc://irc.freenode.net/#golang">`</span>

View file

@ -1,7 +1,7 @@
---
title: site
linktitle: site
description: The `site` function provides global access the same data as `.Site` page method
description: The `site` function provides global access to the same data as the `.Site` page method.
godocref:
date: 2021-02-11
publishdate: 2021-02-11

View file

@ -86,7 +86,7 @@ The following logical operators are available with `where`:
## Use `where` with `Booleans`
When using booleans you should not put quotation marks.
```go-html-template
{{range where .Pages ".Draft" true}}
{{range where .Pages "Draft" true}}
<p>{{.Title}}</p>
{{end}}
```
@ -95,7 +95,7 @@ When using booleans you should not put quotation marks.
## Use `where` with `intersect`
```go-html-template
{{ range where .Site.Pages ".Params.tags" "intersect" .Params.tags }}
{{ range where .Site.Pages "Params.tags" "intersect" .Params.tags }}
{{ if ne .Permalink $.Permalink }}
{{ .Render "summary" }}
{{ end }}
@ -131,7 +131,7 @@ then ranges through only the first 5 posts in that list:
You can also nest `where` clauses to drill down on lists of content by more than one parameter. The following first grabs all pages in the "blog" section and then ranges through the result of the first `where` clause and finds all pages that are *not* featured:
```go-html-template
{{ range where (where .Pages "Section" "blog" ) ".Params.featured" "!=" true }}
{{ range where (where .Pages "Section" "blog" ) "Params.featured" "!=" true }}
```
## Unset Fields
@ -146,7 +146,7 @@ Only the following operators are available for `nil`
* `!=`, `<>`, `ne`: True if the given field is set.
```go-html-template
{{ range where .Pages ".Params.specialpost" "!=" nil }}
{{ range where .Pages "Params.specialpost" "!=" nil }}
{{ .Content }}
{{ end }}
```
@ -166,12 +166,12 @@ section names to hard-coded values like `"posts"` or `"post"`.
If the user has not set this config parameter in their site config, it
will default to the _section with the most pages_.
The user can override the default in `config.toml`:
The user can override the default:
```toml
{{< code-toggle file="config" >}}
[params]
mainSections = ["blog", "docs"]
```
{{< /code-toggle >}}
[intersect]: /functions/intersect/
[wherekeyword]: https://www.techonthenet.com/sql/where.php