You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<!-- If you do, you will break its first literal usage on this page. -->
18
18
<!--more-->
19
19
20
-
You can define a content summary manually, in front matter, or automatically. A manual content summary takes precedence over a front matter summary, and a front matter summary takes precedence over an automatic summary.
20
+
You can define a summary manually, in front matter, or automatically. A manual summary takes precedence over a front matter summary, and a front matter summary takes precedence over an automatic summary.
21
21
22
22
Review the [comparison table](#comparison) below to understand the characteristics of each summary type.
23
23
24
24
## Manual summary
25
25
26
-
Use a `<!--more-->` divider to indicate the end of the content summary. Hugo will not render the summary divider itself.
26
+
Use a `<!--more-->` divider to indicate the end of the summary. Hugo will not render the summary divider itself.
27
27
28
-
{{< code file=content/sample.md >}}
28
+
{{< code file=content/example.md >}}
29
29
+++
30
30
title: 'Example'
31
31
date: 2024-05-26T09:10:33-07:00
32
32
+++
33
33
34
-
Thénardier was not mistaken. The man was sitting there, and letting
35
-
Cosette get somewhat rested.
34
+
This is the first paragraph.
36
35
37
36
<!--more-->
38
37
39
-
The inn-keeper walked round the brushwood and presented himself
40
-
abruptly to the eyes of those whom he was in search of.
38
+
This is the second paragraph.
41
39
{{< /code >}}
42
40
43
-
When using the Emacs Org Mode [content format], use a `# more` divider to indicate the end of the content summary.
41
+
When using the Emacs Org Mode [content format], use a `# more` divider to indicate the end of the summary.
44
42
45
43
[content format]: /content-management/formats/
46
44
47
45
## Front matter summary
48
46
49
47
Use front matter to define a summary independent of content.
50
48
51
-
{{< code file=content/sample.md >}}
49
+
{{< code file=content/example.md >}}
52
50
+++
53
51
title: 'Example'
54
52
date: 2024-05-26T09:10:33-07:00
55
-
summary: 'Learn more about _Les Misérables_ by Victor Hugo.'
53
+
summary: 'This summary is independent of the content.'
56
54
+++
57
55
58
-
Thénardier was not mistaken. The man was sitting there, and letting
59
-
Cosette get somewhat rested. The inn-keeper walked round the
60
-
brushwood and presented himself abruptly to the eyes of those whom
61
-
he was in search of.
56
+
This is the first paragraph.
57
+
58
+
This is the second paragraph.
62
59
{{< /code >}}
63
60
64
61
## Automatic summary
65
62
66
-
If you have not defined the summary manually or in front matter, Hugo automatically defines the summary based on the [`summaryLength`] in your site configuration.
63
+
If you do not define the summary manually or in front matter, Hugo automatically defines the summary based on the [`summaryLength`] in your site configuration.
(`int`) Applicable to automatic summaries, the approximate number of words to render when calling the [`Summary`] method on a `Page` object. Default is `70`.
449
+
(`int`) Applicable to [automatic summaries], the minimum number of words to render when calling the [`Summary`] method on a `Page` object. In this case the `Summary` method returns the content, truncated to the paragraph closest to the `summaryLength`.
description: Returns the content summary of the given page.
3
+
description: Returns the summary of the given page.
4
4
categories: []
5
5
keywords: []
6
6
action:
7
7
related:
8
8
- methods/page/Truncated
9
+
- methods/page/Content
10
+
- methods/page/ContentWithoutSummary
9
11
- methods/page/Description
10
12
returnType: template.HTML
11
13
signatures: [PAGE.Summary]
@@ -15,11 +17,9 @@ action:
15
17
<!-- If you do, you will break its first literal usage on this page. -->
16
18
<!--more-->
17
19
18
-
There are three ways to define the [content summary]:
20
+
You can define a [summary] manually, in front matter, or automatically. A manual summary takes precedence over a front matter summary, and a front matter summary takes precedence over an automatic summary.
19
21
20
-
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.
21
-
2. Manually split the content with a `<!--more-->` tag in Markdown. Everything before the tag is included in the summary.
22
-
3. Create a `summary` field in front matter.
22
+
[summary]: /content-management/summaries/
23
23
24
24
To list the pages in a section with a summary beneath each link:
25
25
@@ -30,4 +30,20 @@ To list the pages in a section with a summary beneath each link:
30
30
{{ end }}
31
31
```
32
32
33
-
[content summary]: /content-management/summaries/
33
+
Depending on content length and how you define the summary, the summary may be equivalent to the content itself. To determine whether the content length exceeds the summary length, use the [`Truncated`] method on a `Page` object. This is useful for conditionally rendering a “read more” link:
Copy file name to clipboardExpand all lines: content/en/methods/page/Truncated.md
+6-10Lines changed: 6 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,17 +10,11 @@ action:
10
10
signatures: [PAGE.Truncated]
11
11
---
12
12
13
-
There are three ways to define the [content summary]:
13
+
You can define a [summary] manually, in front matter, or automatically. A manual summary takes precedence over a front matter summary, and a front matter summary takes precedence over an automatic summary.
14
14
15
-
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.
16
-
2. Manually split the content with a `<--more-->` tag in Markdown. Everything before the tag is included in the summary.
17
-
3. Create a `summary` field in front matter.
15
+
[summary]: /content-management/summaries/
18
16
19
-
{{% note %}}
20
-
The `Truncated` method returns `false` if you define the summary in front matter.
21
-
{{% /note %}}
22
-
23
-
The `Truncated` method returns `true` if the content length exceeds the summary length. This is useful for rendering a "read more" link:
17
+
The `Truncated` method returns `true` if the content length exceeds the summary length. This is useful for conditionally rendering a "read more" link:
24
18
25
19
```go-html-template
26
20
{{ range .Pages }}
@@ -32,4 +26,6 @@ The `Truncated` method returns `true` if the content length exceeds the summary
32
26
{{ end }}
33
27
```
34
28
35
-
[content summary]: /content-management/summaries/
29
+
{{% note %}}
30
+
The `Truncated` method returns `false` if you define the summary in front matter.
0 commit comments