mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-25 22:00:58 +02:00
Merge commit 'de0df119b504a91c9e1f442b07954f366ffb2932'
This commit is contained in:
@@ -1,25 +1,27 @@
|
||||
---
|
||||
title: Summary
|
||||
description: Returns the content summary of the given page.
|
||||
description: Returns the summary of the given page.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related:
|
||||
- methods/page/Truncated
|
||||
- methods/page/Content
|
||||
- methods/page/ContentWithoutSummary
|
||||
- methods/page/Description
|
||||
returnType: template.HTML
|
||||
signatures: [PAGE.Summary]
|
||||
---
|
||||
|
||||
<!-- Do not remove the manual summary divider below. -->
|
||||
<!-- If you do, you will break its first literal usage on this page. -->
|
||||
{{% comment %}}
|
||||
Do not remove the manual summary divider below.
|
||||
If you do, you will break its first literal usage on this page.
|
||||
{{% /comment %}}
|
||||
<!--more-->
|
||||
|
||||
There are three ways to define the [content summary]:
|
||||
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.
|
||||
|
||||
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.
|
||||
3. Create a `summary` field in front matter.
|
||||
[summary]: /content-management/summaries/
|
||||
|
||||
To list the pages in a section with a summary beneath each link:
|
||||
|
||||
@@ -30,4 +32,20 @@ To list the pages in a section with a summary beneath each link:
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
[content summary]: /content-management/summaries/
|
||||
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:
|
||||
|
||||
[`Truncated`]: /methods/page/truncated
|
||||
|
||||
```go-html-template
|
||||
{{ range .Pages }}
|
||||
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
|
||||
{{ .Summary }}
|
||||
{{ if .Truncated }}
|
||||
<a href="{{ .RelPermalink }}">Read more...</a>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
The `Truncated` method returns `false` if you define the summary in front matter.
|
||||
{{% /note %}}
|
||||
|
Reference in New Issue
Block a user