【问题标题】:How to avoid duplicate pages with collections using jekyll paginate v2?如何使用 jekyll paginate v2 避免带有集合的重复页面?
【发布时间】:2017-10-15 14:47:22
【问题描述】:

我遵循了安装 paginate v2 并对集合进行分页的方法,但是对于 paginator 创建的每个页面,我都会获得一个额外的“示例集合”顶级页面链接。

这里是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.md YAML 中的永久链接条目,但这只是导致 jekyll 处理器无法找到 examplecol/index.html。

【问题讨论】:

    标签: jekyll paginator


    【解决方案1】:

    我花了很多时间反复试验,但我在标题中找到了解决方案。

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

    因此,该站点会找到对 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>
    

    由于分页器页面是自动生成的,您可以将它们过滤掉:

    <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>
    

    【讨论】:

      猜你喜欢
      • 2020-08-22
      • 2020-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-24
      • 2022-10-03
      • 2017-10-20
      相关资源
      最近更新 更多