首页 > 解决方案 > 雨果没有从前面的事情中呈现摘要

问题描述

根据Hugo 内容摘要指南,我可以通过 3 种方式定义摘要(按优先级最高的顺序列出):

  1. 使用<!--more-->标签告诉 Hugo 应该使用多少文章作为摘要
  2. 使用summary前面的变量以使用自定义摘要
  3. 让 Hugo 默认使用文章的前 70 个字

首先,这是我为各个页面准备的模板:

{{ 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被忽略了,文章中的单词被用作摘要:datesummary

在此处输入图像描述

然后我像这样使用<!--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

解决方案


这个特性是在Hugo 0.55.0中通过issue #5800引入的。

升级到 Hugo 0.55.0 或以上版本解决问题


推荐阅读