HUGO
Menu
GitHub 87548 stars Mastodon

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


Last updated: January 1, 0001
Improve this page