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

问题描述 投票:0回答:6

我最近将 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.

相关页面的开头如下:

---
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. 

它位于

mysite/content/posts/YYYY-MM-DD-title.md

layouts
目录为空。但是,
themes
目录包含book主题。这个主题也是在
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

为什么我的帖子无法正确呈现?我该如何解决它?

wordpress github export custom-wordpress-pages hugo
6个回答
88
投票

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

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

您可以通过以下方式执行此操作:

git submodule init
git submodule update

然后您的项目将毫无错误地加载。


9
投票

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

这两份文件的前面内容似乎非常不同。我认为

type: post
可能是罪魁祸首。

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

这些链接也可能有帮助:
头条|雨果
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学术主题,请尝试这个:

$ hugo mod clean
$ hugo server

$ hugo mod clean
$ hugo mod get -u ./...
$ hugo server

参考: 错误:文件“未找到”或“无法提取”|故障排除


1
投票

就我而言,我错过了这一步:

echo theme = \"hugo-future-imperfect-slim\" >> config.toml

这会将您的主题添加到配置中。之后,它使用主题中正确的Kinds /布局元素。快速入门中的更多信息:https://gohugo.io/getting-started/quick-start/


0
投票
git submodule init
git submodule update

对我有用!

谢谢,马克·瓦格纳

© www.soinside.com 2019 - 2024. All rights reserved.