hugo - hugo 不会渲染单页布局,而是使用 _default 单页布局
问题描述
)
我正在尝试为 hugo.io 创建自己的主题。到目前为止,一切正常。我唯一的问题是,我无法让 hugo 为单节内容呈现自定义布局。
对于帖子,这很好用:
- index.html 被正确调用
- “布局/帖子”中的 single.html 被正确调用
- 对于教程,列表布局可以正常工作
- 所有文件和列表的永久链接正常工作
问题: * 对于教程,单一布局不会调用“layouts/tutorials/single.html”布局。相反,它使用“layouts/_default/single.html”
我尝试了以下方法:
- 将 type="tutorial" 前言设置添加到所有教程 .md 文件
- 将 layout="tutorial" 前言设置添加到所有教程 .md 文件
- 在“layouts/_default”文件夹中添加一个“tutorial.html”文件(也尝试将其命名为“tutorials.html”)
- 在“layouts”文件夹中添加一个“tutorial.html”文件(同上)
可悲的是,这些都不起作用
我的内容设置:
content
|__ posts
|__ new_post.md
|__ tutorials
|__ new-tutorial.md
我的布局设置(在我的主题文件夹中):
layouts
|__ _default
|__ list.html
|__ single.html
|__ posts
|__ list.html
|__ single.html
|__ tutorials
|__ list.html
|__ single.html
|__index.html
我的单个教程内容(new-tutorial.md):
+++
title = "My new Tutorial"
date: 2019-10-04T14:10:46+02:00
draft: false
type: tutorial
layout: tutorial
+++
# Custom Content Headline
雨果没有错误消息。我希望hugo打开页面“ http://localhost:1313/tutorials/new-tutorial/,其布局位于文件“layouts/tutorials/single.html”中
解决方案
你不应该在你的情况下在 new-tutorial.md 中指定type: tutorial
and 。type:tutorial
Hugo 将默认使用 layouts/tutorials/single.html 作为教程部分,请参阅https://gohugo.io/templates/lookup-order/#examples-layout-lookup-for-regular-pages
new-tutorial.md 的最终结果将如下所示
+++
title = "My new Tutorial"
date: 2019-10-04T14:10:46+02:00
draft: false
+++
# Custom Content Headline
推荐阅读
- python - “while”循环过早退出(python 3)
- mysql - MySQL子查询作为别名 - 未知列错误
- c# - AutoMapper 不映射嵌套的复杂类型
- ffmpeg - 使用 ffmpeg 将 DTS 转换为 AAC 将语音音频向右移动
- path - 路径问题 - POSIX HFS 无法获取文件夹
- java - Firebase 数据库分页滚动动作
- bash - Bash - 如果主域在文件 A(或管道)中,则从文件 B 中删除域/子域
- android - 将可见性设置为 GONE 不会隐藏 imageView
- c# - glBufferData 不断失败并显示 GL_INVALID_ENUM 即使它不应该
- mongodb - 在 MongoDB 中插入大数据