我不想显示有关的列表页。localhost/about甚至不应该存在。理想情况下,我希望没有一个_index.md文件,但雨果抱怨如果我没有一个。
内容目录"/work/ Content /about“同时具有索引.*和_index.*文件,选择一个。零目标上的.File.Dir。将其包装为if或使用:{{ with .File }{{ .Dir }} { end }
我正在尝试具有以下层次结构
content
-- about
-- use-cases
_index.md
--some-use-case
index.md
-- faq
index.md我应该能够访问localhost/about/use-cases或localhost/about/faq,但不能访问localhost/about。有办法做到这一点吗?
发布于 2021-04-20 17:54:15
有不止一种方法可以做到这一点,但是v0.65.0+的方法是使用Hugo的构建选项。下面是我所做的工作:首先添加箭头指向下面的about/_index.md,这样您的目录结构如下所示:
content
-- about
_index.md <-- discussed below!
-- use-cases
_index.md
--some-use-case
index.md
-- faq
index.md在这个about/_index.md文件中放置以下前端内容。
---
cascade:
_build:
render: always
list: always
_build:
render: never
list: never
---这足以使localhost/about/不存在,并且它下面的内容也存在(这就是cascade部分所做的)。如果要将其重定向到某个位置,则可以在要将其重定向到的页面前面包含以下内容:
---
aliases:
- /about/
---例如,如果您想将其重定向到您的主页,请将上面的aliases列表放在content/_index.md中。
content
_index.md <-- home page metadata & content!
-- about
_index.md
⋮https://stackoverflow.com/questions/67076616
复制相似问题