以标题分类的雨果首页帖子摘要,以Hyde-Hyde为主题

时间:2020-02-17 19:52:48

标签: hugo static-site

我使用Hyde-Hyde主题使用Hugo创建了一个静态网站,但是无法按日期对主页(或帖子页面)上的帖子摘要进行排序。我知道使用其他主题可以解决后排序问题,但是这个问题专门针对使其与Hyde-Hyde主题配合使用。下面的可复制代码示例:

以下是使用Hyde-Hyde主题(及其exampleSite内容)获取新的Hugo网站的代码:

~/$ hugo new site mySite
~/$ cd mySite
~/mySite$ git clone https://github.com/htr3n/hyde-hyde.git themes/hyde-hyde
~/mySite$ rm -rf themes/hyde-hyde/.git themes/hyde-hyde/.gitmodules
~/mySite$ mv themes/hyde-hyde/exampleSite/* .

我们现在可以构建站点并通过以下方式在本地提供服务:

~/mySite$ hugo
~/mySite$ hugo serve

...告诉我们,我们的网站可以在http://localhost:1313/

上访问

如果单击localhost链接,您将看到一个类似于(尽管不完全相同)从the Hyde-Hyde theme homepage链接的“演示”页面的站点。但是,首页(和“帖子”页面)上的帖子没有按日期排序;您会注意到前三篇文章的发布日期为2014年9月,然后是2014年3月,然后是2014年4月。

the github issue I filed,到目前为止,我已经尝试过更改

    {{ with .Data.Pages }}

    {{ with .Data.Pages.ByDate }}

themes/hyde-hyde/layouts/partials/page-list/content.html中 和

{{ range . }}

themes/hyde-hyde/layouts/partials/posts-list.html中的一些不同内容,

但是我无法让帖子按日期在首页和“帖子”页面上显示。

1 个答案:

答案 0 :(得分:2)

关于首页Maiki solved this on the hugo discourse page上的发布顺序。将他的答案放在下面的引号中:

“”“

这是主页,该主题以layouts / index.html呈现:

{{ $paginator := .Paginate (where .Site.RegularPages "Type" "in" site.Params.mainSections) }}
{{ range $paginator.Pages }}

设置好分页器,然后进行调整。您可能想要:

{{ range $paginator.Pages.ByDate.Reverse }}

请注意,它对内容使用默认的排序顺序,而9月帖子加权,而其他帖子则不加权。这也会影响列表。

“”“

...对于我的问题的另一部分,要使帖子正确排列在“帖子”页面上,解决方案是更改

{{range .}}

收件人:

{{ range .ByDate.Reverse }}

themes/hyde-hyde/layouts/partials/posts-list.html