【问题标题】:How to fix the error `found no layout file for "HTML" for "page"` in Hugo CMS?如何修复 Hugo CMS 中的错误`found no layout file for "html" for "page"`?
【发布时间】:2022-02-09 11:26:24
【问题描述】:

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

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

【问题讨论】:

  • 我没有使用 Hugo 的经验,但如果它有助于为您指明正确的方向,我会发表评论。这两份文件的正面问题似乎非常不同。我在想type: post 可能是罪魁祸首。是否需要在'post' 周围加上引号?如果您完全删除 post 前面的内容会发生什么?这些链接也可能是 helfpul:gohugo.io/content-management/front-mattergohugo.io/templates/lookup-order
  • @epsilon42 你是对的,删除type: post 解决了我的问题。如果您提交您的评论作为答案,我会接受并且您将获得赏金(通常在 2-3 天后)。

标签: wordpress github export custom-wordpress-pages hugo


【解决方案1】:

修复:

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

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

你可以这样做:

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

然后您的项目将正确加载。

【讨论】:

  • 非常感谢。这就是问题所在。
【解决方案2】:

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

这两份文件的正面内容似乎非常不同。我认为type: post 可能是罪魁祸首。

如果您完全删除 post front matter 会发生什么?

这些链接也可能是 helfpul:
Front Matter | Hugo
Hugo's Lookup Order | Hugo

【讨论】:

    【解决方案3】:

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

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

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

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

    【讨论】:

      【解决方案4】:

      如果你使用雨果学术主题,请试试这个:

      $ hugo mod clean
      $ hugo server
      

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

      参考: Error: File “not found” or “failed to extract” | Troubleshooting

      【讨论】:

      • 这正是我对这个主题所需要的,因为它在 go.mod 中使用它并且没有使用子模块。谢谢你发帖
      • 这也为我修复了它,尽管我使用不同的主题作为 Hugo 模块。运行 hugo mod get -u 并没有其他任何修复它。
      【解决方案5】:

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

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

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

      【讨论】:

        猜你喜欢
        • 2011-12-13
        • 2012-03-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-18
        • 1970-01-01
        • 1970-01-01
        • 2016-05-07
        相关资源
        最近更新 更多