hugo - 使用 Hyde-Hyde 主题按标题对 Hugo 主页帖子摘要进行排序
问题描述
我用 Hugo 创建了一个静态站点,使用 Hyde-Hyde 主题,但我无法让主页(或帖子页面)上的帖子摘要按日期排序。我知道使用不同的主题可以修复后排序,但这个问题专门是关于让它与 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
链接,您将看到一个类似于(但不完全相同)从Hyde-Hyde 主题主页链接的“演示”页面的站点。但是,主页(和“帖子”页面)上的帖子不是按日期排序的;您会注意到前三个帖子的日期为 2014 年 9 月,然后是 2014 年 3 月,然后是 2014 年 4 月。
根据我提交的 github 问题,到目前为止,我已经尝试更改
{{ 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
,
但我无法让帖子按日期排序显示在主页和“帖子”页面上。
解决方案
关于首页的post order,Maiki在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
推荐阅读
- algorithm - 重叠池资源分配算法
- java - 我怎样才能让我的文本文件变成 40x40 矩阵
- python - tkinter 中的马拉雅拉姆语
- asp.net-core - 如何防止预呈现的 Blazor WebAssembly 应用程序中的内容闪烁?
- ios - Swift - 应用内购买完成后 WebView 为零
- html - 在小屏幕上更改标题视图
- java - Grails 4 Security-ui插件发送验证电子邮件,但不解锁用户
- python - 音频限制器中使用了哪些算法?
- import - 如何快捷地从样式组件中导入
- javascript - 有条件地加载 polyfills & bundles