0

我一直在查看有关堆栈溢出和其他来源的类似问题的多个答案,但根本无法解决我的问题。

我有一个页面,index.md其中包含以下主要内容:

# Feel free to add content and custom Front Matter to this file.
# To modify the layout, see https://jekyllrb.com/docs/themes/#overriding-theme-defaults

title: title
layout: default
pagination: 
  enabled: true
---

这就是我列出我的帖子的方法:

    <!-- 
        Here is the main paginator logic called.
        All calls to site.posts should be replaced by paginator.posts 
    -->
    {% for post in paginator.posts %}
      <li>
        <span class="post-meta">{{ post.date | date: "%b %-d, %Y" }}</span>

        <h2>
          <a class="post-link" href="{{ post.url | relative_url }}">{{ post.title | escape }}</a>
        </h2>
      </li>
    {% endfor %}
  </ul>

  <!-- 
    Showing buttons to move to the next and to the previous list of posts (pager buttons).
  -->
  {% if paginator.total_pages > 1 %}
  <ul class="pager">
      {% if paginator.previous_page %}
      <li class="previous">
          <a href="{{ paginator.previous_page_path | prepend: site.baseurl | replace: '//', '/' }}">&larr; Newer Posts</a>
      </li>
      {% endif %}
      {% if paginator.next_page %}
      <li class="next">
          <a href="{{ paginator.next_page_path | prepend: site.baseurl | replace: '//', '/' }}">Older Posts &rarr;</a>
      </li>
      {% endif %}
  </ul>
  {% endif %}


<div class="pagination">
  {% if paginator.previous_page %}
    <a href="{{ paginator.previous_page_path }}" class="previous">
      Previous
    </a>
  {% else %}
    <span class="previous">Previous</span>
  {% endif %}
  <span class="page_number ">
    Page: {{ paginator.page }} of {{ paginator.total_pages }}
  </span>
  {% if paginator.next_page %}
    <a href="{{ paginator.next_page_path }}" class="next">Next</a>
  {% else %}
    <span class="next ">Next</span>
  {% endif %}
</div>

我已将 gem 添加到插件列表和 gem 文件中并运行 bundle install,我的配置如下所示:

pagination:
  enabled: true
  per_page: 3
  offset: 2
  permalink: '/page/:num/'
  title: ':title - page :num of :max'
  limit: 0
  sort_field: 'date'
  sort_reverse: true

但是,当我运行bundle exec jekyll s我的测试帖子时没有列出。但如果我使用:

{% for post in site.posts%}
{{post.title}}
{% endfor %}

我的测试帖子按我的意图列出。任何可以帮助我解决我做错了什么的人,我根本无法发现它。

4

1 回答 1

1

您是否有特定的理由将其包含offset: 2在 中_config.yml?这将排除前 2 个帖子出现在分页中,因此如果您的项目中没有至少 3 个帖子,则不会显示任何内容。

尝试从配置文件中删除偏移线,重新运行bundle exec jekyll serve,看看功能是否有效。

有关偏移量的使用,请查看jekyll-paginate-v2 README部分“偏移量帖子”。

于 2019-12-15T00:06:32.943 回答