【问题标题】:Sorting Hugo Homepage Post Summaries by Title with Hyde-Hyde theme使用 Hyde-Hyde 主题按标题对 Hugo 主页帖子摘要进行排序
【发布时间】:2020-06-01 19:15:50
【问题描述】:

我使用 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 链接,您将看到一个类似于(但不完全相同)从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 中的一些不同的东西,

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

【问题讨论】:

    标签: hugo static-site


    【解决方案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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多