Hugo 未渲染 list.html

Hugo not rendering list.html

我正在尝试构建一个简单的 Hugo 项目。问题是我正在尝试创建一些基本布局,但在渲染时出现错误。

在 /layouts/_default 里面我有以下内容:

baseof.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ .Site.Title }} | {{ .Title }}>
</head>
<body>
    <header>
        <p>this is a header</p>
    </header>
    <main>
        {{ block "main" . }}
            
        {{ end }}
    </main>
    <footer>
        <p>this is a footer</p>
    </footer>
</body>
</html>

list.html

{{ define "main" }}
<h2>List</h2>
{{.Content}}
<!-- prettier-ignore -->
{{ range .Pages }}
<div>
    <a href="{{.Permalink}}">{{.Title}}</a>
    <p>{{ dateFormat "Monday, Jan 2, 2006" .Date }}</p>
</div>
{{ end }}
<!-- prettier-ignore -->
{{ end }}

single.html

{{ define "main" }}
<h1>{{ .Title }}</h1>
<h2>{{ .PublishDate }}</h2>
{{ .Content }}
<!-- prettier-ignore -->
{{ end }}

当我尝试 运行 时,出现以下错误(single.htmllist.html 的错误相同):

2020/09/12 20:33:30 Failed to render pages: render of "page" failed: execute of template failed: html/template:_default/single.html: ends in a non-text context: {stateRCDATA delimNone urlPartNone jsCtxRegexp attrNone elementTitle }

你能给我一些建议吗?

这是直接来自 Go 本身的错误:package html/template

ErrEndContext:“... ends in a non-text context: ...

示例:

<div
  <div title="no close quote>
  <script>f()

讨论:

Executed templates should produce a DocumentFragment of HTML.

Templates that end without closing tags will trigger this error.
Templates that should not be used in an HTML context or that produce incomplete Fragments should not be executed directly.

{{define "main"}} <script>{{template "helper"}}</script> {{end}}
{{define "helper"}} document.write(' <div title=" ') {{end}}

"helper" does not produce a valid document fragment, so should not be Executed directly.

简化您的 single.html 页面以检查您的 baseof.html base template 是否存在问题。

如上所述,不仅 <title> 是可疑的,而且 <meta> 标签也没有关闭:

<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{{ .Site.Title }} | {{ .Title }}> 

应该是

<title>{{ .Site.Title }} | {{ .Title }}</title>