按Hyde-Hyde主题按标题排序的Hugo主页帖子摘要

问题描述 投票:1回答:1

我使用Hude-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 }}

to

    {{ with .Data.Pages.ByDate }}

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

{{ range . }}

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

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

hugo static-site
1个回答
1
投票

关于主页上的发布顺序,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

© www.soinside.com 2019 - 2024. All rights reserved.