根据Hugo content summary guide ,我可以通过 3 种方式定义摘要(按最高优先级列出):
<!--more-->
标签告诉 Hugo 应该使用多少文章作为摘要 summary
在前面的变量中使用自定义摘要首先,这是我为各个页面提供的模板:
{{ partial "header" . }}
{{ partial "nav" . }}
<section class="section">
<div class="container">
<div class="subtitle tags is-6 is-pulled-right">
{{ if .Params.tags }}
{{ partial "tags" .Params.tags }}
{{ end }}
</div>
{{if not .Date.IsZero }}
<h2 class="subtitle is-6">{{ .Date.Format "January 2, 2006" }}</h2>
{{ end }}
<h1 class="title">{{ .Title }}</h1>
{{ if .Site.Params.Info.related }}
<div class="related">{{ partial "related" . }}</div>
{{ end }}
<div class="content">
<h1 id="summary">Summary</h1>
{{ .Summary }}
<h1 id="toc">Table of Contents</h1>
{{ .TableOfContents }}
{{ .Content }}
</div>
</div>
</section>
{{ partial "footer" . }}
这是我制作的示例文章:
---
title: "Test"
date: 2019-11-23T19:51:44-06:00
draft: true
summary: "This is a simple placeholder summary defined in the front matter"
---
This is a simple placeholder written in the article
# Section 1
Hello world!
title
和 date
渲染就好了,但是,summary
被忽略,文章中的词用作摘要:然后我使用了
<!--more-->
像这样标记:---
title: "Test"
date: 2019-11-23T19:51:44-06:00
draft: true
summary: "This is a simple placeholder summary defined in the front matter"
---
This is a simple placeholder written in the article
<!--more-->
# Section 1
Hello world!
它就像一个魅力......
因此,内容摘要的方法 1 和 3 有效,但方法 2 无效。我无法获得
summary
的原因是什么?前端要渲染吗?
最佳答案
此功能是在 Hugo 0.55.0 中引入的通过 issue #5800 .
升级到 Hugo 0.55.0 或更高版本 解决问题
关于雨果没有从正面渲染摘要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59014231/