如何修复 Hugo CMS 中“页面”的“HTML”没有布局文件的错误?

9 wordpress export github custom-wordpress-pages hugo

我最近将我的 WordPress 页面中的内容导入 Hugo。当我运行时,hugo serve我收到以下错误消息:

WARN 2020/02/17 20:51:06 found no layout file for "HTML" for "page": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.
Run Code Online (Sandbox Code Playgroud)

有问题的页面是这样开始的:

---
linktitle: "The Title of the Post"
title: "The Title of the Post"
author: "Franz Drollig"
type: post
date: 2020-01-09T14:41:55+00:00
url: /the-title-of-post/
categories:
  - Uncategorized
weight: 10

---


This is the content of the post. This is the second sentence of the post. 
Run Code Online (Sandbox Code Playgroud)

它位于mysite/content/posts/YYYY-MM-DD-title.md.

layouts目录是空的。但是,该themes目录包含书籍主题。这个主题也在config.toml.

另一个帖子,如下所示,正确呈现。

---
author: "Michael Henderson"
date: 2014-09-28
linktitle: Creating a New Theme
menu:
  main:
    parent: tutorials
next: /tutorials/github-pages-blog
prev: /tutorials/automated-deployments
title: Creating a New Theme
weight: 10
---


## Introduction
Run Code Online (Sandbox Code Playgroud)

为什么我的帖子没有正确呈现?我该如何解决?

小智 24

使固定:

好的,这是可能发生的事情:

您有一个作为 git 子模块添加的主题,并且您最近重新克隆了您的项目。你猜怎么着?您的子模块也需要重新下载。

你可以这样做:

  • git子模块初始化
  • git子模块更新

然后您的项目将加载而不会出错。

  • 太感谢了。这就是问题所在。 (3认同)

eps*_*n42 9

我没有使用 Hugo 的经验,但我想如果它有助于为您指明正确的方向,我会发表评论。

这两份文件的前言似乎非常不同。我想这type: post可能是罪魁祸首。

如果您完全删除帖子前面的内容会发生什么?

这些链接也可能有帮助:
Front Matter | Hugo
Hugo 的查找顺序 | 雨果


小智 8

您必须创建所需的布局;默认情况下,页面布局命名为 single.html,部分布局命名为 list.html。

即使您不会将它们用作真正的模板,您也必须创建它以避免出现警告。

因此,在layout/_default: single.html list.html 中创建这些文件。另外,如果您觉得适用,请在每个文件中使用 Hugo 模板写一些注释,如下所示:

{{ "<!-- Layout with no content to avoid WARN message about missing page layout -->" | safeHTML }}


小智 5

如果您使用hugo学术主题,请尝试以下操作:

\n
$ hugo mod clean\n$ hugo server\n
Run Code Online (Sandbox Code Playgroud)\n

或者

\n
$ hugo mod clean\n$ hugo mod get -u ./...\n$ hugo server\n
Run Code Online (Sandbox Code Playgroud)\n

参考:\n错误:找不到文件 \xe2\x80\x9c\xe2\x80\x9d 或 \xe2\x80\x9c 无法提取\xe2\x80\x9d | 故障排除

\n

  • 这正是我这个主题所需要的,因为它在 go.mod 中需要它并且没有使用子模块。感谢您的发表 (2认同)