Merge commit '8b9803425e63e1b1801f8d5d676e96368d706722'

This commit is contained in:
Bjørn Erik Pedersen
2024-06-21 09:41:24 +02:00
475 changed files with 7408 additions and 4720 deletions

View File

@@ -1,6 +1,6 @@
---
title: AllTranslations
description: Returns all translation of the given page, including the given page.
description: Returns all translations of the given page, including the current language.
categories: []
keywords: []
action:
@@ -63,9 +63,9 @@ And this template:
{{ with .AllTranslations }}
<ul>
{{ range . }}
{{ $langName := or .Language.LanguageName .Language.Lang }}
{{ $langCode := or .Language.LanguageCode .Language.Lang }}
<li><a href="{{ .RelPermalink }}" hreflang="{{ $langCode }}">{{ .LinkTitle }} ({{ $langName }})</a></li>
<li>
<a href="{{ .RelPermalink }}" hreflang="{{ .Language.LanguageCode }}">{{ .LinkTitle }} ({{ or .Language.LanguageName .Language.Lang }})</a>
</li>
{{ end }}
</ul>
{{ end }}

View File

@@ -5,7 +5,7 @@ categories: []
keywords: []
action:
related: []
returnType: files.ContentClass
returnType: string
signatures: [PAGE.BundleType]
---

View File

@@ -63,4 +63,4 @@ Render the code owners for each content page:
Combine this method with [`resources.GetRemote`] to retrieve names and avatars from your Git provider by querying their API.
[`resources.GetRemote`]: functions/resources/getremote
[`resources.GetRemote`]: /functions/resources/getremote/

View File

@@ -13,7 +13,7 @@ action:
signatures: [PAGE.Content]
---
The `Content` method on a `Page` object renders markdown and shortcodes to HTML. The content does not include front matter.
The `Content` method on a `Page` object renders Markdown and shortcodes to HTML. The content does not include front matter.
[shortcodes]: /getting-started/glossary/#shortcode

View File

@@ -74,7 +74,7 @@ Terms
{{% note %}}
Once you have captured the taxonomy object, use any of the [taxonomy methods] to sort, count, or capture a subset of its weighted pages.
[taxonomy methods]: /methods/taxonomy
[taxonomy methods]: /methods/taxonomy/
{{% /note %}}
Learn more about [taxonomy templates].

View File

@@ -33,7 +33,7 @@ The date is a [time.Time] value. Format and localize the value with the [`time.F
In the example above we explicitly set the date in front matter. With Hugo's default configuration, the `Date` method returns the front matter value. This behavior is configurable, allowing you to set fallback values if the date is not defined in front matter. See&nbsp;[details].
[`time.Format`]: /functions/time/format
[`time.Format`]: /functions/time/format/
[details]: /getting-started/configuration/#configure-dates
[time methods]: /methods/time
[time methods]: /methods/time/
[time.Time]: https://pkg.go.dev/time#Time

View File

@@ -10,7 +10,7 @@ action:
signatures: [PAGE.Description]
---
Conceptually different that a [content summary], a page description is typically used in metadata about the page.
Conceptually different from a [content summary], a page description is typically used in metadata about the page.
{{< code-toggle file=content/recipes/sushi.md fm=true >}}
title = 'How to make spicy tuna hand rolls'
@@ -25,4 +25,4 @@ description = 'Instructions for making spicy tuna hand rolls.'
</head>
{{< /code >}}
[content summary]: /content-management/summaries
[content summary]: /content-management/summaries/

View File

@@ -29,7 +29,7 @@ The expiry date is a [time.Time] value. Format and localize the value with the [
In the example above we explicitly set the expiry date in front matter. With Hugo's default configuration, the `ExpiryDate` method returns the front matter value. This behavior is configurable, allowing you to set fallback values if the expiry date is not defined in front matter. See&nbsp;[details].
[`time.Format`]: /functions/time/format
[`time.Format`]: /functions/time/format/
[details]: /getting-started/configuration/#configure-dates
[time methods]: /methods/time
[time methods]: /methods/time/
[time.Time]: https://pkg.go.dev/time#Time

View File

@@ -22,7 +22,9 @@ content/
└── book-2.md
```
Code defensively by verifying file existence as shown in each of the examples below.
{{% note %}}
Code defensively by verifying file existence as shown in the examples below.
{{% /note %}}
## Methods
@@ -80,13 +82,17 @@ The path separators (slash or backslash) in `Path`, `Dir`, and `Filename` depend
{{ end }}
```
###### Lang
###### IsContentAdapter
(`string`) The language associated with the given file.
{{< new-in 0.126.0 >}}
(`bool`) Reports whether the file is a [content adapter].
[content adapter]: /content-management/content-adapters/
```go-html-template
{{ with .File }}
{{ .Lang }}
{{ .IsContentAdapter }}
{{ end }}
```
@@ -110,6 +116,16 @@ The path separators (slash or backslash) in `Path`, `Dir`, and `Filename` depend
{{ end }}
```
###### Section
(`string`) The name of the top level section in which the file resides.
```go-html-template
{{ with .File }}
{{ .Section }}
{{ end }}
```
###### TranslationBaseName
(`string`) The file name, excluding the extension and language identifier.
@@ -157,9 +173,10 @@ ContentBaseName|a|b|news
Dir|news/|news/b/|news/
Ext|md|md|md
Filename|/home/user/...|/home/user/...|/home/user/...
Lang|en|en|en
IsContentAdapter|false|false|false
LogicalName|a.en.md|index.en.md|_index.en.md
Path|news/a.en.md|news/b/index.en.md|news/_index.en.md
Section|news|news|news
TranslationBaseName|a|index|_index
UniqueID|15be14b...|186868f...|7d9159d...
@@ -171,13 +188,7 @@ Some of the pages on a site may not be backed by a file. For example:
- Taxonomy pages
- Term pages
Without a backing file, Hugo will throw a warning if you attempt to access a `.File` property. For example:
```text
WARN .File.ContentBaseName on zero object. Wrap it in if or with...
```
To code defensively, first check for file existence:
Without a backing file, Hugo will throw an error if you attempt to access a `.File` property. To code defensively, first check for file existence:
```go-html-template
{{ with .File }}

View File

@@ -21,7 +21,7 @@ In a URL, whether absolute or relative, the [fragment] links to an `id` attribut
path fragment
```
Hugo assigns an `id` attribute to each markdown [ATX] and [setext] heading within the page content. You can override the `id` with a [markdown attribute] as needed. This creates the relationship between an entry in the [table of contents] (TOC) and a heading on the page.
Hugo assigns an `id` attribute to each Markdown [ATX] and [setext] heading within the page content. You can override the `id` with a [Markdown attribute] as needed. This creates the relationship between an entry in the [table of contents] (TOC) and a heading on the page.
Use the `Fragments` method on a `Page` object to create a table of contents with the `Fragments.ToHTML` method, or by [walking] the `Fragments.Map` data structure.
@@ -31,21 +31,21 @@ Headings
: (`map`) A nested map of all headings on the page. Each map contains the following keys: `ID`, `Level`, `Title` and `Headings`. To inspect the data structure:
```go-html-template
<pre>{{ .Fragments.Headings | jsonify (dict "indent" " ") }}</pre>
<pre>{{ debug.Dump .Fragments.Headings }}</pre>
```
HeadingsMap
: (`slice`) A slice of maps of all headings on the page, with first-level keys for each heading. Each map contains the following keys: `ID`, `Level`, `Title` and `Headings`. To inspect the data structure:
```go-html-template
<pre>{{ .Fragments.HeadingsMap | jsonify (dict "indent" " ") }}</pre>
<pre>{{ debug.Dump .Fragments.HeadingsMap }}</pre>
```
Identifiers
: (`slice`) A slice containing the `id` of each heading on the page. To inspect the data structure:
```go-html-template
<pre>{{ .Fragments.Identifiers | jsonify (dict "indent" " ") }}</pre>
<pre>{{ debug.Dump .Fragments.Identifiers }}</pre>
```
Identifiers.Contains ID
@@ -100,7 +100,7 @@ When using the `Fragments` methods within a shortcode, call the shortcode using
[fragment]: /getting-started/glossary/#fragment
[markdown attribute]: /getting-started/glossary/#markdown-attribute
[setext]: https://spec.commonmark.org/0.30/#setext-headings
[table of contents]: /methods/page/tableofcontents
[table of contents]: /methods/page/tableofcontents/
[walking]: /getting-started/glossary/#walk
[`tableofcontents`]: /methods/page/tableofcontents
[`tableofcontents`]: /methods/page/tableofcontents/
[render hook]: /getting-started/glossary/#render-hook

View File

@@ -17,4 +17,4 @@ action:
To get the exact word count, use the [`WordCount`] method.
[`WordCount`]: /methods/page/wordcount
[`WordCount`]: /methods/page/wordcount/

View File

@@ -13,7 +13,7 @@ aliases: [/functions/getpage]
The `GetPage` method is also available on a `Site` object. See&nbsp;[details].
[details]: /methods/site/getpage
[details]: /methods/site/getpage/
When using the `GetPage` method on the `Page` object, specify a path relative to the current directory or relative to the content directory.
@@ -36,7 +36,7 @@ content/
└── _index.md
```
The examples below depict the result of rendering works/paintings/the-mona-list.md with a single page template:
The examples below depict the result of rendering works/paintings/the-mona-lisa.md with a single page template:
```go-html-template
{{ with .GetPage "starry-night" }}

View File

@@ -14,5 +14,5 @@ action:
Use in conjunction with the [`Related`] method on a [`Pages`] object. See&nbsp;[details].
[`Pages`]: /methods/pages/
[`Related`]: /methods/pages/related
[`Related`]: /methods/pages/related/
[details]: /content-management/related/#index-content-headings-in-related-content

View File

@@ -98,5 +98,5 @@ Gaining a thorough understanding of context is critical for anyone writing templ
{{% /note %}}
[context]: /getting-started/glossary/#context
[`with`]: /functions/go-template/with
[`else`]: /functions/go-template/else
[`with`]: /functions/go-template/with/
[`else`]: /functions/go-template/else/

View File

@@ -1,6 +1,6 @@
---
title: IsAncestor
description: Reports whether PAGE1 in an ancestor of PAGE2.
description: Reports whether PAGE1 is an ancestor of PAGE2.
categories: []
keywords: []
action:
@@ -96,5 +96,5 @@ Gaining a thorough understanding of context is critical for anyone writing templ
{{% /note %}}
[context]: /getting-started/glossary/#context
[`with`]: /functions/go-template/with
[`else`]: /functions/go-template/else
[`with`]: /functions/go-template/with/
[`else`]: /functions/go-template/else/

View File

@@ -1,6 +1,6 @@
---
title: IsDescendant
description: Reports whether PAGE1 in a descendant of PAGE2.
description: Reports whether PAGE1 is a descendant of PAGE2.
categories: []
keywords: []
action:
@@ -95,5 +95,5 @@ Gaining a thorough understanding of context is critical for anyone writing templ
{{% /note %}}
[context]: /getting-started/glossary/#context
[`with`]: /functions/go-template/with
[`else`]: /functions/go-template/else
[`with`]: /functions/go-template/with/
[`else`]: /functions/go-template/else/

View File

@@ -11,7 +11,7 @@ action:
By default, Hugo evaluates the keywords when creating collections of [related content].
[related content]: /content-management/related
[related content]: /content-management/related/
{{< code-toggle file=content/recipes/sushi.md fm=true >}}
title = 'How to make spicy tuna hand rolls'
@@ -32,7 +32,7 @@ Or use the [delimit] function:
{{ delimit .Keywords ", " ", and " }} → tuna, sriracha, nori, and rice
```
[delimit]: /functions/collections/delimit
[delimit]: /functions/collections/delimit/
Keywords are also a useful [taxonomy]:
@@ -43,4 +43,4 @@ keyword = 'keywords'
category = 'categories'
{{< /code-toggle >}}
[taxonomy]: /content-management/taxonomies
[taxonomy]: /content-management/taxonomies/

View File

@@ -34,7 +34,7 @@ Lang
```
LanguageCode
: (`string`) The language code from the site configuration.
: (`string`) The language code from the site configuration. Falls back to `Lang` if not defined.
```go-html-template
{{ .Language.LanguageCode }} → de-DE
@@ -61,5 +61,5 @@ Weight
{{ .Language.Weight }} → 2
```
[details]: /methods/site/language
[details]: /methods/site/language/
[RFC 5646]: https://datatracker.ietf.org/doc/html/rfc5646

View File

@@ -33,8 +33,8 @@ In the example above we explicitly set the last modification date in front matte
Learn more about [date configuration].
[`gitinfo`]: /methods/page/gitinfo
[`time.format`]: /functions/time/format
[`gitinfo`]: /methods/page/gitinfo/
[`time.format`]: /functions/time/format/
[date configuration]: /getting-started/configuration/#configure-dates
[time methods]: /methods/time
[time methods]: /methods/time/
[time.time]: https://pkg.go.dev/time#time

View File

@@ -12,7 +12,7 @@ action:
The `LinkTitle` method returns the `linkTitle` field as defined in front matter, falling back to the value returned by the [`Title`] method.
[`Title`]: /methods/page/title
[`Title`]: /methods/page/title/
{{< code-toggle file=content/articles/healthy-desserts.md fm=true >}}
title = 'Seventeen delightful recipes for healthy desserts'

View File

@@ -65,7 +65,7 @@ With the `PrevInSection` and `NextInSection` methods, the navigation sort order
For example, with a page collection sorted by title, the navigation sort order will use Hugos default sort order. This is probably not what you want or expect. For this reason, the Next and Prev methods on a Pages object are generally a better choice.
[date]: /methods/page/date
[weight]: /methods/page/weight
[linkTitle]: /methods/page/linktitle
[title]: /methods/page/title
[date]: /methods/page/date/
[weight]: /methods/page/weight/
[linkTitle]: /methods/page/linktitle/
[title]: /methods/page/title/

View File

@@ -75,7 +75,7 @@ In the last example, the collection includes pages in the resources subdirectory
{{% note %}}
When used with a `Site` object, the `Pages` method recursively returns all pages within the site. See&nbsp;[details].
[details]: /methods/site/pages
[details]: /methods/site/pages/
{{% /note %}}
```go-html-template

View File

@@ -28,7 +28,7 @@ Although simple to invoke, with the `Paginator` method you can neither filter no
The [`Paginate`] method is more flexible, and strongly recommended.
[`paginate`]: /methods/page/paginate
[`paginate`]: /methods/page/paginate/
{{% /note %}}
{{% note %}}

View File

@@ -29,6 +29,7 @@ Content:
title = 'Example'
date = 2023-01-01
draft = false
[params]
display_toc = false
{{< /code-toggle >}}

View File

@@ -17,8 +17,9 @@ With this front matter:
{{< code-toggle file=content/news/annual-conference.md >}}
title = 'Annual conference'
date = 2023-10-17T15:11:37-07:00
[params]
display_related = true
[author]
[params.author]
email = 'jsmith@example.org'
name = 'John Smith'
{{< /code-toggle >}}
@@ -38,6 +39,6 @@ In the template example above, each of the keys is a valid identifier. For examp
{{ index .Params "key-with-hyphens" }} → 2023
```
[`index`]: /functions/collections/indexfunction
[`index`]: /functions/collections/indexfunction/
[chaining]: /getting-started/glossary/#chain
[identifiers]: /getting-started/glossary/#identifier

View File

@@ -21,7 +21,7 @@ action:
{{% note %}}
The parent section of a regular page is the [current section].
[current section]: /methods/page/currentsection
[current section]: /methods/page/currentsection/
{{% /note %}}
Consider this content structure:

View File

@@ -0,0 +1,157 @@
---
title: Path
description: Returns the logical path of the given page.
categories: []
keywords: []
action:
related:
- methods/page/File
- methods/page/RelPermalink
returnType: string
signatures: [PAGE.Path]
toc: true
---
{{< new-in 0.123.0 >}}
The `Path` method on a `Page` object returns the logical path of the given page, regardless of whether the page is backed by a file.
[logical path]: /getting-started/glossary#logical-path
```go-html-template
{{ .Path }} → /posts/post-1
```
This value is neither a file path nor a relative URL. It is a logical identifier for each page, independent of content format, language, and URL modifiers.
{{% note %}}
Beginning with the release of [v0.92.0] in January 2022, Hugo emitted a warning whenever calling the `Path` method. The warning indicated that this method would change in a future release.
The meaning of, and value returned by, the `Path` method on a `Page` object changed with the release of [v0.123.0] in February 2024.
[v0.92.0]: https://github.com/gohugoio/hugo/releases/tag/v0.92.0
[v0.123.0]: https://github.com/gohugoio/hugo/releases/tag/v0.123.0
{{% /note %}}
To determine the logical path for pages backed by a file, Hugo starts with the file path, relative to the content directory, and then:
1. Strips the file extension
2. Strips the language identifier
3. Converts the result to lower case
4. Replaces spaces with hyphens
The value returned by the `Path` method on a `Page` object is independent of content format, language, and URL modifiers such as the `slug` and `url` front matter fields.
## Examples
### Monolingual site
Note that the logical path is independent of content format and URL modifiers.
File path|Front matter slug|Logical path
:--|:--|:--
`content/_index.md`||`/`
`content/posts/_index.md`||`/posts`
`content/posts/post-1.md`|`foo`|`/posts/post-1`
`content/posts/post-2.html`|`bar`|`/posts/post-2`
### Multilingual site
Note that the logical path is independent of content format, language identifiers, and URL modifiers.
File path|Front matter slug|Logical path
:--|:--|:--
`content/_index.en.md`||`/`
`content/_index.de.md`||`/`
`content/posts/_index.en.md`||`/posts`
`content/posts/_index.de.md`||`/posts`
`content/posts/posts-1.en.md`|`foo`|`/posts/post-1`
`content/posts/posts-1.de.md`|`foo`|`/posts/post-1`
`content/posts/posts-2.en.html`|`bar`|`/posts/post-2`
`content/posts/posts-2.de.html`|`bar`|`/posts/post-2`
### Pages not backed by a file
The `Path` method on a `Page` object returns a value regardless of whether the page is backed by a file.
```text
content/
└── posts/
└── post-1.md <-- front matter: tags = ['hugo']
```
When you build the site:
```text
public/
├── posts/
│ ├── post-1/
│ │ └── index.html .Page.Path = /posts/post-1
│ └── index.html .Page.Path = /posts
├── tags/
│ ├── hugo/
│ │ └── index.html .Page.Path = /tags/hugo
│ └── index.html .Page.Path = /tags
└── index.html .Page.Path = /
```
## Finding pages
These methods, functions, and shortcodes use the logical path to find the given page:
Methods|Functions|Shortcodes
:--|:--|:--
[`Site.GetPage`]|[`urls.Ref`]|[`ref`]
[`Page.GetPage`]|[`urls.RelRef`]|[`relref`]
[`Page.Ref`]||
[`Page.RelRef`]||
[`Shortcode.Ref`]||
[`Shortcode.RelRef`]||
[`urls.Ref`]: /functions/urls/ref/
[`urls.RelRef`]: /functions/urls/relref/
[`Page.GetPage`]: /methods/page/getpage/
[`Site.GetPage`]: /methods/site/getpage/
[`ref`]: /content-management/shortcodes/#ref
[`relref`]: /content-management/shortcodes/#relref
[`Page.Ref`]: /methods/page/ref/
[`Page.RelRef`]: /methods/page/relref/
[`Shortcode.Ref`]: /methods/shortcode/ref
[`Shortcode.RelRef`]: /methods/shortcode/relref
{{% note %}}
Specify the logical path when using any of these methods, functions, or shortcodes. If you include a file extension or language identifier, Hugo will strip these values before finding the page in the logical tree.
{{% /note %}}
## Logical tree
Just as file paths form a file tree, logical paths form a logical tree.
A file tree:
```text
content/
└── s1/
├── p1/
│ └── index.md
└── p2.md
```
The same content represented as a logical tree:
```text
content/
└── s1/
├── p1
└── p2
```
A key difference between these trees is the relative path from p1 to p2:
- In the file tree, the relative path from p1 to p2 is `../p2.md`
- In the logical tree, the relative path is `p2`
{{% note %}}
Remember to use the logical path when using any of the methods, functions, or shortcodes listed in the previous section. If you include a file extension or language identifier, Hugo will strip these values before finding the page in the logical tree.
{{% /note %}}

View File

@@ -13,7 +13,7 @@ action:
signatures: [PAGE.Plain]
---
The `Plain` method on a `Page` object renders markdown and [shortcodes] to HTML, then strips the HTML [tags]. It does not strip HTML [entities]. The plain content does not include front matter.
The `Plain` method on a `Page` object renders Markdown and [shortcodes] to HTML, then strips the HTML [tags]. It does not strip HTML [entities]. The plain content does not include front matter.
To prevent Go's [html/template] package from escaping HTML entities, pass the result through the [`htmlUnescape`] function.
@@ -25,4 +25,4 @@ To prevent Go's [html/template] package from escaping HTML entities, pass the re
[html/template]: https://pkg.go.dev/html/template
[entities]: https://developer.mozilla.org/en-US/docs/Glossary/Entity
[tags]: https://developer.mozilla.org/en-US/docs/Glossary/Tag
[`htmlUnescape`]: /functions/
[`htmlUnescape`]: /functions/transform/htmlunescape/

View File

@@ -15,7 +15,7 @@ action:
The `PlainWords` method on a `Page` object calls the [`Plain`] method, then uses Go's [`strings.Fields`] function to split the result into words.
{{% note %}}
_Fields splits the string s around each instance of one or more consecutive white space characters, as defined by [`unicode.IsSpace`], returning a slice of substrings of s or an empty slice if s contains only white space._
_Fields splits the string s around each instance of one or more consecutive whitespace characters, as defined by [`unicode.IsSpace`], returning a slice of substrings of s or an empty slice if s contains only whitespace._
[`unicode.IsSpace`]: https://pkg.go.dev/unicode#IsSpace
{{% /note %}}
@@ -32,5 +32,5 @@ To determine the approximate number of unique words on a page:
{{ .PlainWords | uniq }} → 42
```
[`Plain`]: /methods/page/plain
[`Plain`]: /methods/page/plain/
[`strings.Fields`]: https://pkg.go.dev/strings#Fields

View File

@@ -66,7 +66,7 @@ With the `PrevInSection` and `NextInSection` methods, the navigation sort order
For example, with a page collection sorted by title, the navigation sort order will use Hugos default sort order. This is probably not what you want or expect. For this reason, the Next and Prev methods on a Pages object are generally a better choice.
[date]: /methods/page/date
[weight]: /methods/page/weight
[linkTitle]: /methods/page/linktitle
[title]: /methods/page/title
[date]: /methods/page/date/
[weight]: /methods/page/weight/
[linkTitle]: /methods/page/linktitle/
[title]: /methods/page/title/

View File

@@ -29,7 +29,7 @@ The publish date is a [time.Time] value. Format and localize the value with the
In the example above we explicitly set the publish date in front matter. With Hugo's default configuration, the `PublishDate` method returns the front matter value. This behavior is configurable, allowing you to set fallback values if the publish date is not defined in front matter. See&nbsp;[details].
[`time.Format`]: /functions/time/format
[`time.Format`]: /functions/time/format/
[details]: /getting-started/configuration/#configure-dates
[time methods]: /methods/time
[time methods]: /methods/time/
[time.Time]: https://pkg.go.dev/time#Time

View File

@@ -25,7 +25,7 @@ This is useful when rendering a page in a plain text [output format].
[Shortcodes] within the content are not rendered. To get the raw content with shortcodes rendered, use the [`RenderShortcodes`] method on a `Page` object.
[shortcodes]: /getting-started/glossary/#shortcode
[`RenderShortcodes`]: /methods/page/rendershortcodes
[`RenderShortcodes`]: /methods/page/rendershortcodes/
{{% /note %}}
[output format]: /templates/output-formats
[output format]: /templates/output-formats/

View File

@@ -72,7 +72,7 @@ In the last example, the collection includes pages in the resources subdirectory
{{% note %}}
When used with the `Site` object, the `RegularPages` method recursively returns all regular pages within the site. See&nbsp;[details].
[details]: /methods/site/regularpages
[details]: /methods/site/regularpages/
{{% /note %}}
```go-html-template

View File

@@ -70,6 +70,6 @@ layouts/_default/li.html
See [content views] for more examples.
[content views]: /templates/views
[`partial`]: /functions/partials/include
[content views]: /templates/views/
[`partial`]: /functions/partials/include/
[content type]: /getting-started/glossary/#content-type

View File

@@ -22,11 +22,12 @@ Use this method in shortcode templates to compose a page from multiple content f
For example:
{{< code file=layouts/shortcodes/include.html >}}
{{ $p := site.GetPage (.Get 0) }}
{{ $p.RenderShortcodes }}
{{ with site.GetPage (.Get 0) }}
{{ .RenderShortcodes }}
{{ end }}
{{< /code >}}
Then in your markdown:
Then call the shortcode in your Markdown:
{{< code file=content/about.md lang=md >}}
{{%/* include "/snippets/services.md" */%}}
@@ -34,14 +35,14 @@ Then in your markdown:
{{%/* include "/snippets/leadership.md" */%}}
{{< /code >}}
Each of the included markdown files can contain calls to other shortcodes.
Each of the included Markdown files can contain calls to other shortcodes.
## Shortcode notation
In the example above it's important to understand the difference between the two delimiters used when calling a shortcode:
- `{{</* myshortcode */>}}` tells Hugo that the rendered shortcode does not need further processing. For example, the shortcode content is HTML.
- `{{%/* myshortcode */%}}` tells Hugo that the rendered shortcode needs further processing. For example, the shortcode content is markdown.
- `{{%/* myshortcode */%}}` tells Hugo that the rendered shortcode needs further processing. For example, the shortcode content is Markdown.
Use the latter for the "include" shortcode described above.
@@ -75,4 +76,4 @@ https://example.org/privacy/
An *emphasized* word.
```
Note that the shortcode within the content file was rendered, but the surrounding markdown was preserved.
Note that the shortcode within the content file was rendered, but the surrounding Markdown was preserved.

View File

@@ -47,5 +47,5 @@ Render with [Pandoc]:
{{ .RenderString $opts $s }} → <p>H<sub>2</sub>O</p>
```
[markup identifier]: /content-management/formats/#list-of-content-formats
[markup identifier]: /content-management/formats/#classification
[pandoc]: https://www.pandoc.org/

View File

@@ -75,11 +75,11 @@ With the `GetMatch` and `Match` methods, Hugo determines a match using a case-in
{{% include "functions/_common/glob-patterns.md" %}}
[`resources.ByType`]: /functions/resources/ByType
[`resources.GetMatch`]: /functions/resources/ByType
[`resources.Get`]: /functions/resources/ByType
[`resources.Match`]: /functions/resources/ByType
[`resources`]: /functions/resources
[`resources.ByType`]: /functions/resources/ByType/
[`resources.GetMatch`]: /functions/resources/ByType/
[`resources.Get`]: /functions/resources/ByType/
[`resources.Match`]: /functions/resources/ByType/
[`resources`]: /functions/resources/
[glob pattern]: https://github.com/gobwas/glob#example
[media type]: https://en.wikipedia.org/wiki/Media_type
[page bundle]: /getting-started/glossary/#page-bundle

View File

@@ -1,6 +1,6 @@
---
title: Scratch
description: Creates a "scratch pad" on the given page to store and manipulate data.
description: Returns a "scratch pad" on the given page to store and manipulate data.
categories: []
keywords: []
action:
@@ -9,6 +9,7 @@ action:
- functions/collections/NewScratch
returnType: maps.Scratch
signatures: [PAGE.Scratch]
toc: true
aliases: [/extras/scratch/,/doc/scratch/,/functions/scratch]
---
@@ -16,8 +17,28 @@ The `Scratch` method on a `Page` object creates a [scratch pad] to store and man
To create a locally scoped scratch pad that is not attached to a `Page` object, use the [`newScratch`] function.
[`Store`]: /methods/page/store
[`newScratch`]: functions/collections/newscratch
[`Store`]: /methods/page/store/
[`newScratch`]: /functions/collections/newscratch/
[scratch pad]: /getting-started/glossary/#scratch-pad
{{% include "methods/page/_common/scratch-methods.md" %}}
## Determinate values
The `Scratch` 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 not determinate 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 }}
{{ .Store.Get "mykey" }}
```
You can also trigger content rendering with the `FuzzyWordCount`, `Len`, `Plain`, `PlainWords`, `ReadingTime`, `Summary`, `Truncated`, and `WordCount` methods. For example:
```go-html-template
{{ $noop := .WordCount }}
{{ .Store.Get "mykey" }}
```

View File

@@ -50,5 +50,5 @@ This is similar to using the [`Type`] method with the `where` function
However, if the `type` field in front matter has been defined on one or more pages, the page collection based on `Type` will be different than the page collection based on `Section`.
[`where`]: /functions/collections/where
[`Type`]: /methods/page/type
[`where`]: /functions/collections/where/
[`Type`]: /methods/page/type/

View File

@@ -35,11 +35,11 @@ content/
│ ├── bidding.md
│ └── payment.md
├── books/
│ ├── _index.md <-- front matter: weight = 10
│ ├── _index.md <-- front matter: weight = 20
│ ├── book-1.md
│ └── book-2.md
├── films/
│ ├── _index.md <-- front matter: weight = 20
│ ├── _index.md <-- front matter: weight = 10
│ ├── film-1.md
│ └── film-2.md
└── _index.md

View File

@@ -12,7 +12,7 @@ action:
See [Site methods].
[Site methods]: /methods/site
[Site methods]: /methods/site/
```go-html-template
{{ .Site.Title }}

View File

@@ -14,15 +14,22 @@ Access to the `Sitemap` method on a `Page` object is restricted to [sitemap temp
## Methods
ChangeFreq
: (`string`) How frequently a page is likely to change. Valid values are `always`, `hourly`, `daily`, `weekly`, `monthly`, `yearly`, and `never`. Default is "" (change frequency omitted from rendered sitemap).
changefreq
: (`string`) How frequently a page is likely to change. Valid values are `always`, `hourly`, `daily`, `weekly`, `monthly`, `yearly`, and `never`. With the default value of `""` Hugo will omit this field from the sitemap. See [details](https://www.sitemaps.org/protocol.html#changefreqdef).
```go-html-template
{{ .Sitemap.ChangeFreq }}
```
Priority
: (`float`) The priority of a page relative to any other page on the site. Valid values range from 0.0 to 1.0. Default is -1 (priority omitted from rendered sitemap).
disable {{< new-in 0.125.0 >}}
: (`bool`) Whether to disable page inclusion. Default is `false`. Set to `true` in front matter to exclude the page.
```go-html-template
{{ .Sitemap.Disable }}
```
priority
: (`float`) The priority of a page relative to any other page on the site. Valid values range from 0.0 to 1.0. With the default value of `-1` Hugo will omit this field from the sitemap. See [details](https://www.sitemaps.org/protocol.html#priority).
```go-html-template
{{ .Sitemap.Priority }}

View File

@@ -52,10 +52,10 @@ Produces a list of links to each home page:
</ul>
```
To render a link to home page of the primary (first) language:
To render a link to the home page of the site corresponding to the default content language:
```go-html-template
{{ with .Sites.First }}
{{ with .Sites.Default }}
<a href="{{ .Home.Permalink }}">{{ .Title }}</a>
{{ end }}
```

View File

@@ -1,6 +1,6 @@
---
title: Store
description: Creates a persistent "scratch pad" on the given page to store and manipulate data.
description: Returns a persistent "scratch pad" on the given page to store and manipulate data.
categories: []
keywords: []
action:
@@ -9,6 +9,7 @@ action:
- functions/collections/NewScratch
returnType: maps.Scratch
signatures: [PAGE.Store]
toc: true
aliases: [/functions/store]
---
@@ -16,8 +17,8 @@ The `Store` method on a `Page` object creates a persistent [scratch pad] to stor
To create a locally scoped scratch pad that is not attached to a `Page` object, use the [`newScratch`] function.
[`Scratch`]: /methods/page/scratch
[`newScratch`]: functions/collections/newscratch
[`Scratch`]: /methods/page/scratch/
[`newScratch`]: /functions/collections/newscratch/
[scratch pad]: /getting-started/glossary/#scratch-pad
## Methods
@@ -102,3 +103,23 @@ Removes the given key.
{{ .Store.Set "greeting" "Hello" }}
{{ .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 not determinate 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 }}
{{ .Store.Get "mykey" }}
```
You can also trigger content rendering with the `FuzzyWordCount`, `Len`, `Plain`, `PlainWords`, `ReadingTime`, `Summary`, `Truncated`, and `WordCount` methods. For example:
```go-html-template
{{ $noop := .WordCount }}
{{ .Store.Get "mykey" }}
```

View File

@@ -11,10 +11,14 @@ action:
signatures: [PAGE.Summary]
---
<!-- Do not remove the manual summary divider below. -->
<!-- If you do, you will break its first literal usage on this page. -->
<!--more-->
There are three ways to define the [content summary]:
1. Let Hugo create the summary based on the first 70 words. You can change the number of words by setting the `summaryLength` in your site configuration.
2. Manually split the content with a `<--more-->` tag in markdown. Everything before the tag is included in the summary.
2. Manually split the content with a `<!--more-->` tag in Markdown. Everything before the tag is included in the summary.
3. Create a `summary` field in front matter.
To list the pages in a section with a summary beneath each link:
@@ -26,4 +30,4 @@ To list the pages in a section with a summary beneath each link:
{{ end }}
```
[content summary]: /content-management/summaries
[content summary]: /content-management/summaries/

View File

@@ -8,9 +8,10 @@ action:
- methods/page/Fragments
returnType: template.HTML
signatures: [PAGE.TableOfContents]
aliases: [/content-management/toc/]
---
The `TableOfContents` method on a `Page` object returns an ordered or unordered list of the markdown [ATX] and [setext] headings within the page content.
The `TableOfContents` method on a `Page` object returns an ordered or unordered list of the Markdown [ATX] and [setext] headings within the page content.
[atx]: https://spec.commonmark.org/0.30/#atx-headings
[setext]: https://spec.commonmark.org/0.30/#setext-headings

View File

@@ -20,19 +20,21 @@ title = 'About us'
{{ .Title }} → About us
```
With section pages not backed by a file, the `Title` method returns the section name, pluralized and converted to title case.
To disable [pluralization]:
With section, taxonomy, and term pages not backed by a file, the `Title` method returns the section name, capitalized and pluralized. You can disable these transformations by setting [`capitalizeListTitles`] and [`pluralizeListTitles`] in your site configuration. For example:
{{< code-toggle file=hugo >}}
capitalizeListTitles = false
pluralizeListTitles = false
{{< /code-toggle >}}
To change the [title case style], specify one of `ap`, `chicago`, `go`, `firstupper`, or `none`:
You can change the capitalization style in your site configuration to one of `ap`, `chicago`, `go`, `firstupper`, or `none`. For example:
{{< code-toggle file=hugo >}}
titleCaseStyle = "ap"
titleCaseStyle = "firstupper"
{{< /code-toggle >}}
[pluralization]: /functions/inflect/pluralize
[title case style]: /getting-started/configuration/#configure-title-case
See [details].
[`capitalizeListTitles`]: /getting-started/configuration/#capitalizelisttitles
[`pluralizeListTitles`]: /getting-started/configuration/#pluralizelisttitles
[details]: /getting-started/configuration/#configure-title-case

View File

@@ -1,6 +1,6 @@
---
title: Translations
description: Returns all translation of the given page, excluding the current language.
description: Returns all translations of the given page, excluding the current language.
categories: []
keywords: []
action:
@@ -63,9 +63,9 @@ And this template:
{{ with .Translations }}
<ul>
{{ range . }}
{{ $langName := or .Language.LanguageName .Language.Lang }}
{{ $langCode := or .Language.LanguageCode .Language.Lang }}
<li><a href="{{ .RelPermalink }}" hreflang="{{ $langCode }}">{{ .LinkTitle }} ({{ $langName }})</a></li>
<li>
<a href="{{ .RelPermalink }}" hreflang="{{ .Language.LanguageCode }}">{{ .LinkTitle }} ({{ or .Language.LanguageName .Language.Lang }})</a>
</li>
{{ end }}
</ul>
{{ end }}

View File

@@ -13,7 +13,7 @@ action:
There are three ways to define the [content summary]:
1. Let Hugo create the summary based on the first 70 words. You can change the number of words by setting the `summaryLength` in your site configuration.
2. Manually split the content with a `<--more-->` tag in markdown. Everything before the tag is included in the summary.
2. Manually split the content with a `<--more-->` tag in Markdown. Everything before the tag is included in the summary.
3. Create a `summary` field in front matter.
{{% note %}}
@@ -32,4 +32,4 @@ The `Truncated` method returns `true` if the content length exceeds the summary
{{ end }}
```
[content summary]: /content-management/summaries
[content summary]: /content-management/summaries/

View File

@@ -17,4 +17,4 @@ action:
To round up to nearest multiple of 100, use the [`FuzzyWordCount`] method.
[`FuzzyWordCount`]: /methods/page/fuzzywordcount
[`FuzzyWordCount`]: /methods/page/fuzzywordcount/

View File

@@ -7,7 +7,7 @@ cascade:
---
<!--
Files within this headless branch bundle are markdown snippets. Each file must contain front matter delimiters, though front matter fields are not required.
Files within this headless branch bundle are Markdown snippets. Each file must contain front matter delimiters, though front matter fields are not required.
Include the rendered content using the "include" shortcode.
-->

View File

@@ -8,4 +8,4 @@ Hugo generates one or more files per page when building a site. For example, whe
[taxonomy]: /getting-started/glossary/#taxonomy
[term]: /getting-started/glossary/#term
[page kind]: /getting-started/glossary/#page-kind
[details]: /templates/output-formats
[details]: /templates/output-formats/