【问题标题】:In Jekyll, site.posts returns nothing在 Jekyll 中,site.posts 不返回任何内容
【发布时间】:2012-09-14 23:08:54
【问题描述】:

我用 Jekyll 写博客。在我的source/index.html(我重新配置了_config.yml中的路径)我写过:

{{ site.posts }} 

但是当我编译它时,它没有给出任何结果。我确信我有帖子,它们是按预期编译和工作的。

我不知道从哪里开始故障排除,有其他人遇到过这样的问题吗?

【问题讨论】:

    标签: ruby yaml jekyll liquid


    【解决方案1】:

    site.post 返回液化 Jekyll::Post 对象的数组。你可以通过简单的写来查看帖子的数量:

    {{ site.posts.size }} 
    

    你可以遍历它们写作:

    <ul>
    {% for post in site.posts %}
      <li class="post">
        <h1><a href="{{ post.url }}">{{ post.title }}</a></h1>
      </li>
    {% endfor %}
    </ul>
    

    【讨论】:

      【解决方案2】:

      在 Jekyll 中,帖子需要位于 _posts 文件夹中才能包含在 {{ site.posts }} 变量中。

      您很可能只是省略了文件夹名称中的下划线。

      【讨论】:

        【解决方案3】:

        验证发帖时间,它发生在过去,以后的帖子不会添加到site.posts

        【讨论】:

          猜你喜欢
          • 2020-12-03
          • 1970-01-01
          • 2017-07-20
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-04-27
          • 2019-04-06
          • 2012-02-15
          相关资源
          最近更新 更多