提问人:jjk 提问时间:5/5/2019 更新时间:3/14/2023 访问量:9041
如何更改 hugo 中的主页?
How to change the homepage in hugo?
问:
我怎样才能有 /posts 作为主页?
我应该重定向,更改 hugo 1配置中的 baseURL 还是在 主题 2配置?
脚注
1 https://gohugo.io/getting-started/configuration/
2 https://github.com/luizdepra/hugo-coder/wiki/Configurations
答:
您可以修改 home.html 文件,因为 index.html 文件正在嵌入它,而 index 中没有其他内容.html
https://github.com/luizdepra/hugo-coder/blob/master/layouts/partials/home.html
在上述文件中进行更改 theme/layouts/partials/home.html 这些更改将在您保存文件后立即在网站上生效(如果您已经在运行$ hugo server -D
)
评论
list.html
对我来说,它有助于将文件添加到我的主题中。以下是其内容:layouts/index.html
{{ define "main" }}
{{ $pag := .Paginate (where site.RegularPages "Type" "in" site.Params.mainSections ) 6 }}
<div class="archive-body">
{{ range $pag.Pages }}
{{ .Render "li" }}
{{ end }}
</div>
{{ partial "pagination" . }}
{{ end }}
"li"
是一个部分 HTML 模板,它为我呈现了一个页面。
然后我不得不在我的 .由于我的内容位于目录内,因此这是配置。mainSections
config.toml
content/post
[params]
mainSections = ["post"]
由于这是一个列表,因此您应该能够添加多个部分。例如,如果你的内容是传播的,比如说在和之间,等等。不过,我还没有尝试过。content/post
content/articles
我知道这是一个老问题,但对我来说,将特定的 Markdown 页面设置为登录页面的最简单方法是简单地创建一个来覆盖我的主题,并将其放入其中:
这样,我可以保留所有主题的样式,而不必担心编辑模板,而只专注于创建内容。作为 hugo 的新手,这作为鹈鹕的替代品效果很好。layouts/index.html
<script>window.location = "/mainlist"</script>
save_as: index.html
正如 Saif 所提到的,您需要替换位于“partials”文件夹中的文件中的内容。home.html
# Remove
{{ partialCached "home/avatar.html" . }}
{{ partialCached "home/author.html" . }}
{{ partialCached "home/socials.html" . }}
# Add
{{ partialCached "posts/li.html" . }}
这应该在主页上列出您的博客。但是,博客列表也带有自己的标题。这意味着您将拥有两个标题。要从博客列表中删除标题,请从 .index.html
# Remove these lines from the file
<header>
<h1 class="title">
<a class="title-link" href="{{ .Permalink | safeURL }}">
{{ title (i18n (lower .Title)) | default .Title }}
</a>
</h1>
</header>
现在您将拥有一个带有博客列表且没有 2 个标题的主页。
确保对您编辑的文件进行备份。
评论