【问题标题】:How to change the homepage in hugo?如何在hugo中更改主页?
【发布时间】:2021-01-23 22:51:43
【问题描述】:

如何将 /posts 作为主页?

我应该重定向,更改 hugo 1config 中的 baseURL 还是更改 主题 2config?

脚注

1https://gohugo.io/getting-started/configuration/

2https://github.com/luizdepra/hugo-coder/wiki/Configurations

【问题讨论】:

    标签: hugo


    【解决方案1】:

    你可以修改 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

    【讨论】:

    • 谢谢@Saif Azmi。您知道我如何确定 /posts 中的索引基于哪个文件吗?因此,我可以按照您的建议将其内容复制到 home.html 中。此处修改当前文件并没有导致 /posts 索引发生变化:github.com/luizdepra/hugo-coder/tree/master/layouts/partials/…
    • /posts 的索引由list.html 文件呈现。可以在这里找到:github.com/luizdepra/hugo-coder/blob/master/layouts/posts/…
    • 谢谢@Saif Azmi。将 home.html 的内容替换为 list.html 中的内容后,主页变为空。还有其他想法吗?也许我应该强调我的目标:我希望访问者登陆 /posts 来代替主页。类似于wordpress的“使用另一页作为主页”功能。
    • 然后将索引页面中的代码替换为帖子中的代码。
    【解决方案2】:

    对我来说,将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 模板,它为我呈现一个页面。

    然后我必须在我的config.toml 中指定mainSections。由于我的内容位于content/post目录内,所以这里是配置。

    [params]
      mainSections = ["post"]
    

    由于这是一个列表,您应该可以添加多个部分。例如,如果您的内容在content/postcontent/articles 之间传播,等等。不过我没试过。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-22
      • 2016-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多