Summary
返回给定页面的摘要。
Syntax
PAGE.Summary
Returns
template.HTML
您可以手动在 front matter 中定义 摘要,或自动定义。手动摘要优先于 front matter 摘要,front matter 摘要优先于自动摘要。
要列出栏目中的页面并在每个链接下方显示摘要:
{{ range .Pages }}
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ .Summary }}
{{ end }}自动 .Summary 可能会在中间截断块标签(例如,blockquote),导致浏览器恢复结束标签。有关详情和避免此问题的方法,请参阅 自动摘要。
根据内容长度以及您如何定义摘要,摘要可能等同于内容本身。要确定内容长度是否超过摘要长度,请在 Page 对象上使用 Truncated 方法。这对于条件渲染"阅读更多"链接很有用:
{{ range .Pages }}
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ .Summary }}
{{ if .Truncated }}
<a href="{{ .RelPermalink }}">阅读更多...</a>
{{ end }}
{{ end }}如果您在 front matter 中定义摘要,Truncated 方法返回 false。