简体   繁体   English

雨果不呈现 list.html

[英]Hugo not rendering list.html

I am trying to build a simple Hugo project.我正在尝试构建一个简单的 Hugo 项目。 The problem is that I am trying to create some basic layouts and I get an error when rendering.问题是我正在尝试创建一些基本布局,但在渲染时出现错误。

Inside the /layouts/_default I have the following:在 /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 }}

When I try running, I get the following error (same error both for single.html and for list.html ):当我尝试运行时,出现以下错误( 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 } 2020/09/12 20:33:30 渲染页面失败:“页面”渲染失败:模板执行失败:html/template:_default/single.html:以非文本上下文结束:{stateRCDATA delimNone urlPartNone jsCtxRegexp attrNone elementTitle }

Can you give me any suggestions?你能给我任何建议吗?

This is an error directly from Go itself: package html/template这是直接来自 Go 本身的错误: package html/template

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

Example:例子:

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

Discussion:讨论:

Executed templates should produce a DocumentFragment of HTML.执行的模板应生成 HTML 的DocumentFragment

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.不应在 HTML 上下文中使用或产生不完整片段的模板不应直接执行。

 {{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. helper ”不会产生有效的文档片段,因此不应直接执行。

Simplify your single.html page in order to check if your baseof.html base template has the issue.简化您的single.html页面以检查您的baseof.html基本模板是否有问题。

Not only <title> is suspect, as noted, but the <meta> tags are not closed either:如前所述,不仅<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM