Skip to content

Commit 5fbef43

Browse files
committed
More updates for v0.123.00
Closes gohugoio#2385 Closes gohugoio#2421
1 parent ff25748 commit 5fbef43

File tree

13 files changed

+469
-105
lines changed

13 files changed

+469
-105
lines changed

content/en/content-management/diagrams.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ keywords: [diagrams,drawing]
66
menu:
77
docs:
88
parent: content-management
9-
weight: 245
10-
weight: 245
9+
weight: 260
10+
weight: 260
1111
toc: true
1212
---
1313
{{< new-in 0.93.0 >}}

content/en/content-management/front-matter.md

+38-6
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ date = 2024-02-02T04:14:54-08:00
3636
draft = false
3737
weight = 10
3838
[params]
39-
myparam = 42
40-
tags = ['red','blue']
39+
author = 'John Smith'
4140
{{< /code-toggle >}}
4241

4342
Front matter fields may be [scalar], [arrays], or [maps] containing [boolean], [integer], [float], or [string] values. Note that the TOML format also supports date/time values using unquoted strings.
@@ -194,6 +193,8 @@ path
194193

195194
###### params
196195

196+
{{< new-in 0.123.0 >}}
197+
197198
(`map`) A map of custom [page parameters].
198199

199200
[page parameters]: #parameters
@@ -262,23 +263,52 @@ path
262263

263264
## Parameters
264265

265-
Specify custom page parameters, including taxonomy terms, under the `params` key in front matter:
266+
{{< new-in 0.123.0 >}}
267+
268+
Specify custom page parameters under the `params` key in front matter:
266269

267270
{{< code-toggle file=content/example.md fm=true >}}
268271
title = 'Example'
269272
date = 2024-02-02T04:14:54-08:00
270273
draft = false
271274
weight = 10
272275
[params]
273-
myparam = 42
274-
tags = ['red','blue']
276+
author = 'John Smith'
275277
{{< /code-toggle >}}
276278

277279
Access these values from a template using the [`Params`] or [`Param`] method on a `Page` object.
278280

279281
[`param`]: /methods/page/param/
280282
[`params`]: /methods/page/params/
281283

284+
## Taxonomies
285+
286+
Classify content by adding taxonomy terms to front matter. For example, with this site configuration:
287+
288+
{{< code-toggle file=hugo >}}
289+
[taxonomies]
290+
tag = 'tags'
291+
genre = 'genres'
292+
{{< /code-toggle >}}
293+
294+
Add taxonomy terms as shown below:
295+
296+
{{< code file=content/example.md >}}
297+
title = 'Example'
298+
date = 2024-02-02T04:14:54-08:00
299+
draft = false
300+
weight = 10
301+
tags = ['red','blue']
302+
genres = ['mystery','romance']
303+
[params]
304+
author = 'John Smith'
305+
{{< /code >}}
306+
307+
Access taxonomy terms from a template using the [`Params`] or [`GetTerms`] method on a `Page` object:
308+
309+
[`Params`]: /methods/page/params/
310+
[`GetTerms`]: /methods/page/getterms/
311+
282312
## Cascade
283313

284314
Any [node] can pass down to its descendants a set of front matter values.
@@ -356,7 +386,9 @@ If your [content format] is [Emacs Org Mode], you may provide front matter using
356386
#+TITLE: Example
357387
#+DATE: 2024-02-02T04:14:54-08:00
358388
#+DRAFT: false
359-
#+MYPARAM: 42
389+
#+AUTHOR: John Smith
390+
#+GENRES: mystery
391+
#+GENRES: romance
360392
#+TAGS: red
361393
#+TAGS: blue
362394
#+WEIGHT: 10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
---
2+
title: Markdown attributes
3+
description: Use mardown attributes to add HTML attributes when rendering markdown to HTML.
4+
categories: [content management]
5+
keywords: [goldmark,markdown]
6+
menu:
7+
docs:
8+
parent: content-management
9+
weight: 240
10+
weight: 240
11+
toc: true
12+
---
13+
14+
## Overview
15+
16+
Hugo supports markdown attributes on images and block elements including blockquotes, fenced code blocks, headings, horizontal rules, lists, paragraphs, and tables.
17+
18+
For example:
19+
20+
```text
21+
This is a paragraph.
22+
{class="foo bar" id="baz"}
23+
```
24+
25+
With `class` and `id` you can use shorthand notation:
26+
27+
```text
28+
This is a paragraph.
29+
{.foo .bar #baz}
30+
```
31+
32+
Hugo renders both of these to:
33+
34+
```html
35+
<p class="foo bar" id="baz">This is a paragraph.</p>
36+
```
37+
38+
## Block elements
39+
40+
Update your site configuration to enable markdown attributes for block-level elements.
41+
42+
{{< code-toggle file=hugo >}}
43+
[markup.goldmark.parser.attribute]
44+
title = true # default is true
45+
block = true # default is false
46+
{{< /code-toggle >}}
47+
48+
49+
## Standalone images
50+
51+
By default, when the [Goldmark] markdown renderer encounters a standalone image element (no other elements or text on the same line), it wraps the image element within a paragraph element per the [CommonMark specification].
52+
53+
[CommonMark specification]: https://spec.commonmark.org/current/
54+
[Goldmark]: https://github.com/yuin/goldmark
55+
56+
If you were to place an attribute list beneath an image element, Hugo would apply the attributes to the surrounding paragraph, not the image.
57+
58+
To apply attributes to a standalone image element, you must disable the default wrapping behavior:
59+
60+
{{< code-toggle file=hugo >}}
61+
[markup.goldmark.parser]
62+
wrapStandAloneImageWithinParagraph = false # default is true
63+
{{< /code-toggle >}}
64+
65+
## Usage
66+
67+
You may add [global HTML attributes], or HTML attributes specific to the current element type. Consistent with its content security model, Hugo removes HTML event attributes such as `onclick` and `onmouseover`.
68+
69+
[global HTML attributes]: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes
70+
71+
The attribute list consists of one or more key/value pairs, separated by spaces or commas, wrapped by braces. You must quote string values that contain spaces. Unlike HTML, boolean attributes must have both key and value.
72+
73+
For example:
74+
75+
```text
76+
> This is a blockquote.
77+
{class="foo bar" hidden=hidden}
78+
```
79+
80+
Hugo renders this to:
81+
82+
```html
83+
<blockquote class="foo bar" hidden="hidden">
84+
<p>This is a blockquote.</p>
85+
</blockquote>
86+
```
87+
88+
In most cases, place the attribute list beneath the markup element. For headings and fenced code blocks, place the attribute list on the right.
89+
90+
Element|Position of attribute list
91+
:--|:--
92+
blockquote | bottom
93+
fenced code block | right
94+
heading | right
95+
horizontal rule | bottom
96+
image | bottom
97+
list | bottom
98+
paragraph | bottom
99+
table | bottom
100+
101+
For example:
102+
103+
````text
104+
## Section 1 {class=foo}
105+
106+
```bash {class=foo linenos=inline}
107+
declare a=1
108+
echo "${a}"
109+
```
110+
111+
This is a paragraph.
112+
{class=foo}
113+
````
114+
115+
As shown above, the attribute list for fenced code blocks is not limited to HTML attributes. You can also configure syntax highlighting by passing one or more of [these options](/functions/transform/highlight/#options).

content/en/content-management/mathematics.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ keywords: [chemical,chemistry,latex,math,mathjax,tex,typesetting]
77
menu:
88
docs:
99
parent: content-management
10-
weight: 250
11-
weight: 250
10+
weight: 270
11+
weight: 270
1212
toc: true
1313
math: true
1414
---

content/en/content-management/page-resources.md

+107-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ menu:
1010
weight: 80
1111
toc: true
1212
---
13+
1314
Page resources are only accessible from [page bundles](/content-management/page-bundles), those directories with `index.md` or
1415
`_index.md` files at their root. Page resources are only available to the
1516
page with which they are bundled.
@@ -114,7 +115,7 @@ GetMatch
114115
.Resources.Match "*sunset.jpg" 🚫
115116
```
116117

117-
## Page resources metadata
118+
## Metadata
118119

119120
The page resources' metadata is managed from the corresponding page's front matter with an array/table parameter named `resources`. You can batch assign values using [wildcards](https://tldp.org/LDP/GNU-Linux-Tools-Summary/html/x11655.htm).
120121

@@ -201,3 +202,108 @@ the `Name` and `Title` will be assigned to the resource files as follows:
201202
| guide.pdf | `"pdf-file-2.pdf` | `"guide.pdf"` |
202203
| other\_specs.pdf | `"pdf-file-3.pdf` | `"Specification #1"` |
203204
| photo\_specs.pdf | `"pdf-file-4.pdf` | `"Specification #2"` |
205+
206+
## Multilingual
207+
208+
{{< new-in 0.123.0 >}}
209+
210+
By default, with a multilingual single-host site, Hugo does not duplicate shared page resources when building the site.
211+
212+
{{% note %}}
213+
This behavior is limited to markdown content. Shared page resources for other [content formats] are copied into each language bundle.
214+
215+
[content formats]: /content-management/formats/
216+
{{% /note %}}
217+
218+
Consider this site configuration:
219+
220+
{{< code-toggle file=hugo >}}
221+
defaultContentLanguage = 'de'
222+
defaultContentLanguageInSubdir = true
223+
224+
[languages.de]
225+
languageCode = 'de-DE'
226+
languageName = 'Deutsch'
227+
weight = 1
228+
229+
[languages.en]
230+
languageCode = 'en-US'
231+
languageName = 'English'
232+
weight = 2
233+
{{< /code-toggle >}}
234+
235+
And this content:
236+
237+
```text
238+
content/
239+
└── my-bundle/
240+
├── a.jpg <-- shared page resource
241+
├── b.jpg <-- shared page resource
242+
├── c.de.jpg
243+
├── c.en.jpg
244+
├── index.de.md
245+
└── index.en.md
246+
```
247+
248+
With v0.122.0 and earlier, Hugo duplicated the shared page resources, creating copies for each language:
249+
250+
```text
251+
public/
252+
├── de/
253+
│ ├── my-bundle/
254+
│ │ ├── a.jpg <-- shared page resource
255+
│ │ ├── b.jpg <-- shared page resource
256+
│ │ ├── c.de.jpg
257+
│ │ └── index.html
258+
│ └── index.html
259+
├── en/
260+
│ ├── my-bundle/
261+
│ │ ├── a.jpg <-- shared page resource (duplicate)
262+
│ │ ├── b.jpg <-- shared page resource (duplicate)
263+
│ │ ├── c.en.jpg
264+
│ │ └── index.html
265+
│ └── index.html
266+
└── index.html
267+
268+
```
269+
270+
With v0.123.0 and later, Hugo places the shared resources in the page bundle for the default content language:
271+
272+
```text
273+
public/
274+
├── de/
275+
│ ├── my-bundle/
276+
│ │ ├── a.jpg <-- shared page resource
277+
│ │ ├── b.jpg <-- shared page resource
278+
│ │ ├── c.de.jpg
279+
│ │ └── index.html
280+
│ └── index.html
281+
├── en/
282+
│ ├── my-bundle/
283+
│ │ ├── c.en.jpg
284+
│ │ └── index.html
285+
│ └── index.html
286+
└── index.html
287+
```
288+
289+
This approach reduces build times, storage requirements, bandwidth consumption, and deployment times, ultimately reducing cost.
290+
291+
{{% note %}}
292+
To resolve markdown link and image destinations to the correct location, you must use link and image render hooks that capture the page resource with the [`Resources.Get`] method, and then invoke its [`RelPermalink`] method.
293+
294+
By default, with multilingual single-host sites, Hugo enables its [embedded link render hook] and [embedded image render hook] to resolve markdown link and image destinations.
295+
296+
You may override the embedded render hooks as needed, provided they capture the resource as described above.
297+
298+
[embedded link render hook]: /render-hooks/links/#default
299+
[embedded image render hook]: /render-hooks/images/#default
300+
[`Resources.Get`]: /methods/page/resources/#get
301+
[`RelPermalink`]: /methods/resource/relpermalink/
302+
{{% /note %}}
303+
304+
Although duplicating shared page resources is inefficient, you can enable this feature in your site configuration if desired:
305+
306+
{{< code-toggle file=hugo >}}
307+
[markup.goldmark]
308+
duplicateResourceFiles = true
309+
{{< /code-toggle >}}

content/en/content-management/syntax-highlighting.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ keywords: [highlighting,chroma,code blocks,syntax]
66
menu:
77
docs:
88
parent: content-management
9-
weight: 240
10-
weight: 240
9+
weight: 250
10+
weight: 250
1111
toc: true
1212
aliases: [/extras/highlighting/,/extras/highlight/,/tools/syntax-highlighting/]
1313
---

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ See additional examples in the [partial templates] section.
8080
## Usage
8181

8282
{{% note %}}
83-
Unlike `return` statements in other languages, Hugo executes the first occurrence of the `return` statement regardless of its position within logical blocks
83+
Unlike `return` statements in other languages, Hugo executes the first occurrence of the `return` statement regardless of its position within logical blocks.
8484
{{% /note %}}
8585

8686
A partial that returns a value must contain only one `return` statement, placed at the end of the template.

0 commit comments

Comments
 (0)