如何使用jekyll paginate v2避免使用集合重复页面?

时间:2017-10-14 01:18:57

标签: jekyll paginator

我按照方法安装了paginate v2并对一个集合进行了分页,但是我为paginator创建的每个页面都获得了一个额外的“Example Collection”顶级页面链接。

这是example.md

---
layout: page
title: Example Collection
permalink: /example/
pagination: 
  enabled: true
---

{% for post in paginator.posts %}
  <h1>{{ post.title }}</h1>
{% endfor %}

{% if paginator.total_pages > 1 %}
<ul>
  {% if paginator.previous_page %}
  <li>
    <a href="{{ paginator.previous_page_path | prepend: site.baseurl }}">Newer</a>
  </li>
  {% endif %}
  {% if paginator.next_page %}
  <li>
    <a href="{{ paginator.next_page_path | prepend: site.baseurl }}">Older</a>
  </li>
  {% endif %}
</ul>
{% endif %}

这就是我添加到config.yml

的内容
# Collections
collections:
  examplecol:
    output: true
    permalink: /:collection/:path/

# Plugin: Pagination (jekyll-paginate-v2)
pagination:
  collection   :  'examplecol'
  enabled      : true
  debug        : false
  per_page     : 3
  #permalink    : "/page/:num/"
  title        : ":title - Page :num of :max"
  limit        : 0
  sort_field   : "date"
  sort_reverse : true

现在,如果_examplecol文件夹中有超过3个文件,我会将1个以上的example.md实例作为标题中的页面。

如何在包含所有分页页面的标题中只有一个Example Collection实例?我想我错过了一些愚蠢的话。

我尝试删除example.md YAML中的永久链接条目,但这只是为了让jekyll处理器找不到examplecol / index.html。

1 个答案:

答案 0 :(得分:0)

我花了很多试验和错误,但我在标题中找到了解决方案。

当分页器创建包含某些项目的页面时,该站点将它们视为页面并呈现它们。

因此,该网站会找到对my_page.title的所有真实回复并创建页面链接。

 <div class="trigger">
            {% for my_page in site.pages %}
              {% if my_page.title %}
              <a class="page-link" href="{{ my_page.url | relative_url }}">{{ my_page.title | escape }}</a>
              {% endif %}
            {% endfor %}
    </div>

由于paginator页面是autogen,你可以将它们过滤掉:

<div class="trigger">
        {% for my_page in site.pages %}
          {% if my_page.title and my_page.autogen == nil %}
          <a class="page-link" href="{{ my_page.url | relative_url }}">{{ my_page.title | escape }}</a>
          {% endif %}
        {% endfor %}
</div>
相关问题