Skip to content

Commit c4611ea

Browse files
authored
Rework introduction to templating
1 parent 64154fb commit c4611ea

File tree

17 files changed

+418
-537
lines changed

17 files changed

+418
-537
lines changed

.cspell.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020
],
2121
"ignoreRegExpList": [
2222
"# cspell: ignore fenced code blocks",
23-
"^(\\s*`{3,}).*[\\s\\S]*?^\\1",
23+
"^(\\s*`{3,}).*[\\s\\S]*?^\\1$",
2424
"# cspell: ignore words joined with dot",
2525
"\\w+\\.\\w+",
2626
"# cspell: ignore strings within backticks",
2727
"`.+`",
28-
"# cspell: ignore strings within single quotes",
29-
"'.+'",
3028
"# cspell: ignore strings within double quotes",
3129
"\".+\"",
3230
"# cspell: ignore strings within brackets",

content/en/about/hugo-and-gdpr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ aliases: [/privacy/,/gdpr/]
2222
Note that:
2323

2424
* These settings have their defaults setting set to _off_, i.e. how it worked before Hugo `0.41`. You must do your own evaluation of your site and apply the appropriate settings.
25-
* These settings work with the [internal templates](/templates/internal/). Some theme may contain custom templates for embedding services like Google Analytics. In that case these options have no effect.
25+
* These settings work with the [embedded templates](/templates/embedded/). Some theme may contain custom templates for embedding services like Google Analytics. In that case these options have no effect.
2626
* We will continue this work and improve this further in future Hugo versions.
2727

2828
## All privacy settings

content/en/content-management/comments.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ For many websites, this is enough configuration. However, you also have the opti
3737

3838
### Render Hugo's built-in Disqus partial template
3939

40-
Disqus has its own [internal template](/templates/internal/#disqus) available, to render it add the following code where you want comments to appear:
40+
Disqus has its own [internal template](/templates/embedded/#disqus) available, to render it add the following code where you want comments to appear:
4141

4242
```go-html-template
4343
{{ template "_internal/disqus.html" . }}
@@ -66,7 +66,7 @@ Open-source commenting systems:
6666
- [Utterances](https://utteranc.es/)
6767

6868
[configuration]: /getting-started/configuration/
69-
[disquspartial]: /templates/internal/#disqus
69+
[disquspartial]: /templates/embedded/#disqus
7070
[disqussetup]: https://disqus.com/profile/signup/
7171
[forum]: https://discourse.gohugo.io
7272
[front matter]: /content-management/front-matter/

content/en/content-management/toc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ A collection of textile samples lay spread out on the table - Samsa was a travel
110110

111111
Hugo will take this AsciiDoc and create a table of contents store it in the page variable `.TableOfContents`, in the same as described for Markdown.
112112

113-
[conditionals]: /templates/introduction/#conditionals
113+
[conditionals]: /templates/introduction/#conditional-blocks
114114
[front matter]: /content-management/front-matter/
115115
[pagevars]: /methods/page/
116116
[partials]: /templates/partials/

content/en/functions/collections/Where.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ To return a collection of future events:
243243
{{ $futureEvents := where $events "Params.eventDate" "gt" now }}
244244
```
245245

246-
When working with YAML or JSON, or quoted TOML values, custom dates are strings; you cannot compare them with `time.Time` values. String comparisons may be possible if the custom date layout is consistent from one page to the next. However, to be safe, filter the pages by ranging through the collection:
246+
When working with YAML or JSON, or quoted TOML values, custom dates are strings; you cannot compare them with `time.Time` values. String comparisons may be possible if the custom date layout is consistent from one page to the next. To be safe, filter the pages by ranging through the collection:
247247

248248
```go-html-template
249249
{{ $events := where .Site.RegularPages "Type" "events" }}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ action:
1313
signatures: ['template NAME [CONTEXT]']
1414
---
1515

16-
Use the `template` function to execute [internal templates]. For example:
16+
Use the `template` function to execute [embedded templates]. For example:
1717

1818
```go-html-template
1919
{{ range (.Paginate .Pages).Pages }}
@@ -46,4 +46,4 @@ The example above can be rewritten using an [inline partial] template:
4646

4747
[`partial`]: /functions/partials/include/
4848
[inline partial]: /templates/partials/#inline-partials
49-
[internal templates]: /templates/internal/
49+
[embedded templates]: /templates/embedded/

content/en/functions/resources/FromString.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Place this in your baseof.html template:
3737
{{ $m := dict
3838
"hugo_version" hugo.Version
3939
"build_date" (now.Format $rfc3339)
40-
"last_modified" (site.LastChange.Format $rfc3339)
40+
"last_modified" (site.Lastmod.Format $rfc3339)
4141
}}
4242
{{ $json := jsonify $m }}
4343
{{ $r := resources.FromString "site.json" $json }}
@@ -61,7 +61,7 @@ Combine `resources.FromString` with [`resources.ExecuteAsTemplate`] if your stri
6161
{{ $m := dict
6262
"hugo_version" hugo.Version
6363
"build_date" (now.Format $rfc3339)
64-
"last_modified" (site.LastChange.Format $rfc3339)
64+
"last_modified" (site.Lastmod.Format $rfc3339)
6565
}}
6666
{{ $json := jsonify $m }}
6767
`

content/en/functions/strings/ContainsNonSpace.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: strings.ContainsNonSpace
3-
description: Reports whether the given string contains any non-space characters as defined by Unicodes White Space property.
3+
description: Reports whether the given string contains any non-space characters as defined by Unicode's White Space property.
44
categories: []
55
keywords: []
66
action:
@@ -24,7 +24,7 @@ aliases: [/functions/strings.containsnonspace]
2424
{{ strings.ContainsNonSpace "\n abc" }} → true
2525
```
2626

27-
Common white space characters include:
27+
Common whitespace characters include:
2828

2929
```text
3030
'\t', '\n', '\v', '\f', '\r', ' '

content/en/getting-started/glossary.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ A template called with the `.Page.Render` method. See [details](/templates/
9898

9999
###### context
100100

101-
Represented by a dot "." within a [template action](#template-action), context is the current location in a data structure. For example, while iterating over a [collection](#collection) of pages, the context within each iteration is the page's data structure. The context received by each template depends on template type and/or how it was called. See [details](/templates/introduction/#the-dot).
101+
Represented by a dot "." within a [template action](#template-action), context is the current location in a data structure. For example, while iterating over a [collection](#collection) of pages, the context within each iteration is the page's data structure. The context received by each template depends on template type and/or how it was called. See [details](/templates/introduction/#context).
102102

103103
###### default sort order
104104

@@ -363,6 +363,14 @@ A numbered sequence of elements. Unlike Go's [array](#array) data type, slices a
363363

364364
A sequence of bytes. For example, `"What is 6 times 7?"` .
365365

366+
###### string literal (interpreted)
367+
368+
Interpreted string literals are character sequences between double quotes, as in "foo". Within the quotes, any character may appear except a newline and an unescaped double quote. The text between the quotes forms the value of the literal, with backslash escapes interpreted. See [details](https://go.dev/ref/spec#String_literals).
369+
370+
###### string literal (raw)
371+
372+
Raw string literals are character sequences between backticks, as in \`bar\`. Within the backticks, any character may appear except a backtick. Backslashes have no special meaning and the string may contain newlines. Carriage return characters ('\r') inside raw string literals are discarded from the raw string value. See [details](https://go.dev/ref/spec#String_literals).
373+
366374
###### taxonomic weight
367375

368376
Defined in front matter and unique to each taxonomy, this [weight](#weight) determines the sort order of page collections contained within a [taxonomy object](#taxonomy-object). See [details](/templates/taxonomy-templates/#assign-weight).

content/en/methods/page/Path.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Methods|Functions|Shortcodes
108108
[`Shortcode.Ref`]||
109109
[`Shortcode.RelRef`]||
110110

111-
[`urls.Ref`]: functions/urls/ref/
111+
[`urls.Ref`]: /functions/urls/ref/
112112
[`urls.RelRef`]: /functions/urls/relref/
113113
[`Page.GetPage`]: /methods/page/getpage/
114114
[`Site.GetPage`]: /methods/site/getpage/

content/en/methods/page/PlainWords.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ action:
1515
The `PlainWords` method on a `Page` object calls the [`Plain`] method, then uses Go's [`strings.Fields`] function to split the result into words.
1616

1717
{{% note %}}
18-
_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._
18+
_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._
1919

2020
[`unicode.IsSpace`]: https://pkg.go.dev/unicode#IsSpace
2121
{{% /note %}}

content/en/methods/site/Params.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Access the custom parameters by [chaining] the [identifiers]:
3333
{{ .Site.Params.author.name }} → John Smith
3434
3535
{{ $layout := .Site.Params.layouts.rfc_1123 }}
36-
{{ .Site.LastChange.Format $layout }} → Tue, 17 Oct 2023 13:21:02 PDT
36+
{{ .Site.Lastmod.Format $layout }} → Tue, 17 Oct 2023 13:21:02 PDT
3737
```
3838

3939
In the template example above, each of the keys is a valid identifier. For example, none of the keys contains a hyphen. To access a key that is not a valid identifier, use the [`index`] function:

content/en/render-hooks/images.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ block = true
7272
## Examples
7373

7474
{{% note %}}
75-
With inline elements such as images and links, remove leading and trailing white space using the `{{‑ ‑}}` delimiter notation to prevent white space between adjacent inline elements and text.
75+
With inline elements such as images and links, remove leading and trailing whitespace using the `{{‑ ‑}}` delimiter notation to prevent whitespace between adjacent inline elements and text.
7676
{{% /note %}}
7777

7878
In its default configuration, Hugo renders Markdown images according to the [CommonMark specification]. To create a render hook that does the same thing:

content/en/render-hooks/links.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Link render hook templates receive the following context:
5555
## Examples
5656

5757
{{% note %}}
58-
With inline elements such as images and links, remove leading and trailing white space using the `{{‑ ‑}}` delimiter notation to prevent white space between adjacent inline elements and text.
58+
With inline elements such as images and links, remove leading and trailing whitespace using the `{{‑ ‑}}` delimiter notation to prevent whitespace between adjacent inline elements and text.
5959
{{% /note %}}
6060

6161
In its default configuration, Hugo renders Markdown links according to the [CommonMark specification]. To create a render hook that does the same thing:

content/en/templates/internal.md renamed to content/en/templates/embedded.md

Lines changed: 37 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
title: Internal templates
3-
description: Hugo ships with a group of boilerplate templates that cover the most common use cases for static websites.
2+
title: Embedded templates
3+
description: Hugo provides embedded templates for common use cases.
44
categories: [templates]
55
keywords: [internal, analytics,]
66
menu:
@@ -9,12 +9,9 @@ menu:
99
weight: 190
1010
weight: 190
1111
toc: true
12+
aliases: [/templates/internal]
1213
---
1314

14-
{{% note %}}
15-
While the following internal templates are called similar to partials, they do *not* observe the partial template lookup order.
16-
{{% /note %}}
17-
1815
## Disqus
1916

2017
{{% note %}}
@@ -26,7 +23,16 @@ To override Hugo's embedded Disqus template, copy the [source code] to a file wi
2623
[source code]: {{% eturl disqus %}}
2724
{{% /note %}}
2825

29-
Hugo includes an embedded template for [Disqus comments][disqus], a popular commenting system for both static and dynamic websites. To effectively use Disqus, secure a Disqus "shortname" by [signing up for the free service][disqussignup].
26+
Hugo includes an embedded template for [Disqus], a popular commenting system for both static and dynamic websites. To effectively use Disqus, secure a Disqus "shortname" by [signing up] for the free service.
27+
28+
[Disqus]: https://disqus.com
29+
[signing up]: https://disqus.com/profile/signup/
30+
31+
To include the embedded template:
32+
33+
```go-html-template
34+
{{ template "_internal/disqus.html" . }}
35+
```
3036

3137
### Configure Disqus
3238

@@ -45,17 +51,9 @@ Hugo's Disqus template accesses this value with:
4551

4652
You can also set the following in the front matter for a given piece of content:
4753

48-
* `disqus_identifier`
49-
* `disqus_title`
50-
* `disqus_url`
51-
52-
### Use the Disqus template
53-
54-
To add Disqus, include the following line in the templates where you want your comments to appear:
55-
56-
```go-html-template
57-
{{ template "_internal/disqus.html" . }}
58-
```
54+
- `disqus_identifier`
55+
- `disqus_title`
56+
- `disqus_url`
5957

6058
### Conditional loading of Disqus comments
6159

@@ -106,6 +104,12 @@ Hugo includes an embedded template supporting [Google Analytics 4].
106104

107105
[Google Analytics 4]: https://support.google.com/analytics/answer/10089681
108106

107+
To include the embedded template:
108+
109+
```go-html-template
110+
{{ template "_internal/google_analytics.html" . }}
111+
```
112+
109113
### Configure Google Analytics
110114

111115
Provide your tracking ID in your configuration file:
@@ -116,15 +120,7 @@ Provide your tracking ID in your configuration file:
116120
ID = "G-MEASUREMENT_ID"
117121
{{</ code-toggle >}}
118122

119-
### Use the Google Analytics template
120-
121-
Include the Google Analytics internal template in your templates where you want the code to appear:
122-
123-
```go-html-template
124-
{{ template "_internal/google_analytics.html" . }}
125-
```
126-
127-
To create your own template, access the configured ID with `{{ site.Config.Services.GoogleAnalytics.ID }}`.
123+
To use this value in your own template, access the configured ID with `{{ site.Config.Services.GoogleAnalytics.ID }}`.
128124

129125
## Open Graph
130126

@@ -140,6 +136,12 @@ To override Hugo's embedded Open Graph template, copy the [source code] to a fil
140136
Hugo includes an embedded template for the [Open Graph protocol](https://ogp.me/), metadata that enables a page to become a rich object in a social graph.
141137
This format is used for Facebook and some other sites.
142138

139+
To include the embedded template:
140+
141+
```go-html-template
142+
{{ template "_internal/opengraph.html" . }}
143+
```
144+
143145
### Configure Open Graph
144146

145147
Hugo's Open Graph template is configured using a mix of configuration variables and [front-matter](/content-management/front-matter/) on individual pages.
@@ -177,14 +179,6 @@ Various optional metadata can also be set:
177179

178180
If using YouTube this will produce a og:video tag like `<meta property="og:video" content="url">`. Use the `https://youtu.be/<id>` format with YouTube videos (example: `https://youtu.be/qtIqKaDlqXo`).
179181

180-
### Use the Open Graph template
181-
182-
To add Open Graph metadata, include the following line between the `<head>` tags in your templates:
183-
184-
```go-html-template
185-
{{ template "_internal/opengraph.html" . }}
186-
```
187-
188182
## Schema
189183

190184
{{% note %}}
@@ -200,10 +194,10 @@ Hugo includes an embedded template to render [microdata] `meta` elements within
200194

201195
[microdata]: https://html.spec.whatwg.org/multipage/microdata.html#microdata
202196

203-
To call the embedded template from your templates:
197+
To include the embedded template:
204198

205199
```go-html-template
206-
{{ template "_internal/schema.xml" . }}
200+
{{ template "_internal/schema.html" . }}
207201
```
208202

209203
## Twitter Cards
@@ -220,6 +214,12 @@ To override Hugo's embedded Twitter Cards template, copy the [source code] to a
220214
Hugo includes an embedded template for [Twitter Cards](https://developer.twitter.com/en/docs/twitter-for-websites/cards/overview/abouts-cards),
221215
metadata used to attach rich media to Tweets linking to your site.
222216

217+
To include the embedded template:
218+
219+
```go-html-template
220+
{{ template "_internal/twitter_cards.html" . }}
221+
```
222+
223223
### Configure Twitter Cards
224224

225225
Hugo's Twitter Card template is configured using a mix of configuration variables and [front-matter](/content-management/front-matter/) on individual pages.
@@ -254,16 +254,3 @@ NOTE: The `@` will be added for you
254254
```html
255255
<meta name="twitter:site" content="@GoHugoIO"/>
256256
```
257-
258-
### Use the Twitter Cards template
259-
260-
To add Twitter card metadata, include the following line immediately after the `<head>` element in your templates:
261-
262-
```go-html-template
263-
{{ template "_internal/twitter_cards.html" . }}
264-
```
265-
266-
267-
268-
[disqus]: https://disqus.com
269-
[disqussignup]: https://disqus.com/profile/signup/

0 commit comments

Comments
 (0)