我正在尝试使用Hugo创建一个网站,但我不知道如何在我的网站上添加一个页面(帖子工作正常)。
从全新安装开始( v.0.27 64x 用于 windows )并从终端运行以下命令:
> hugo new site soexample
> cd soexample
> git clone https://github.com/parsiya/Hugo-Octopress.git themes\octopress
> hugo new about.md
> echo "Please display me" >> content\about.md
> hugo serve -D -t octopress
我可以看到我的草稿页面是从最后一个命令的输出中呈现的:
...
Built site for language en:
1 of 1 draft rendered
...
但是当我尝试访问http://localhost:1313/about/
或http://localhost:1313/about.html
时,服务器(而不是浏览器)会返回一个白页:
404 page not found
我错过了什么?
答案 0 :(得分:8)
问题似乎来自所选的默认主题,该主题不会在帖子single page之外呈现section。对于初学者来说,主题可能是一个棘手的问题,因为hugo没有默认发布,也没有推荐或支持官方主题(因此初学者可能需要随机选择)。
所以以下命令对我有用:
> hugo new site soexample
> cd soexample
> git clone https://github.com/spf13/hyde.git themes\hyde
> hugo new about.md
> echo "Please display me" >> content\about.md
> hugo serve -D -t hyde
正确呈现了页面http://localhost:1313/about/
。
答案 1 :(得分:3)
为了在Hugo中呈现独立页面,您需要将类型设置为页面,并确保在布局中有一个“单个”模板。
在about.md前端设置'type'到'page'。在_default文件夹下的layouts文件夹中,请确保您有一个single.html文件。
就是这样,现在/ about页面应该正确呈现。
答案 2 :(得分:0)
可能的副本,How to add a new hugo static page?
我已经回答了这个问题,也可以在此处复制粘贴。
我也有类似的要求,以添加静态页面(在这种情况下为aboutus
)。遵循步骤即可达到目的,
content/aboutus/_index.md
layouts/section/aboutus.html
答案 3 :(得分:0)
我认为问题可能与草案有关。
默认情况下,新创建的内容具有draft: false
,并且hugo默认情况下会排除草稿文件。
您可以将其更改为draft: true
或使用--buildDrafts
选项。