Jekyll博客文章在非index.html页面上

8

我从Jekyll网站使用了以下代码片段来在我的index.html页面上分页Jekyll博客文章:

<div class="container">

         <ul class="post-list">
    <!-- This loops through the paginated posts -->
    {% for post in paginator.posts %}
      <h1><a href="{{ post.url }}">{{ post.title }}</a></h1>
      <p class="author">
        <span class="date">{{ post.date }}</span>
      </p>

      <div class="content">
        {{ post.content }}
      </div>
    {% endfor %}

      {% if paginator.total_pages > 1 %}
 <div class="pagination">
  {% if paginator.previous_page %}
    <a href="{{ paginator.previous_page_path | prepend: site.baseurl | replace: '//', '/' }}">&laquo; Prev</a>
  {% else %}
    <span>&laquo; Prev</span>
  {% endif %}

  {% for page in (1..paginator.total_pages) %}
    {% if page == paginator.page %}
      <em>{{ page }}</em>
    {% elsif page == 1 %}
      <a href="{{ '/index.html' | prepend: site.baseurl | replace: '//', '/' }}">{{ page }}</a>
    {% else %}
      <a href="{{ site.paginate_path | prepend: site.baseurl | replace: '//', '/' | replace: ':num', page }}">{{ page }}</a>
    {% endif %}
  {% endfor %}

  {% if paginator.next_page %}
    <a href="{{ paginator.next_page_path | prepend: site.baseurl | replace: '//', '/' }}">Next &raquo;</a>
  {% else %}
    <span>Next &raquo;</span>
  {% endif %}
</div>
{% endif %}

  </ul>

    </div>

然而,当我试图将它添加到/pages/Blog.html页面时,它不起作用。它不显示我在_posts目录中的任何帖子,而是产生一个空容器。我认为这是路径问题。
我已经按要求在Blog.html文件中添加了YAML头。当页面被渲染时,它会生成一个空容器。
1个回答

16
如果你想让你的文章列表url看起来像这样/pages/Blog/
  1. _config.yml文件中设置paginate: 5以激活分页功能。

  2. _config.yml文件中设置paginate_path: pages/Blog/page:num

  3. 将/pages/Blog.html重命名为pages/Blog/index.html


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接