2017-10-14 31 views
1

我遵循這種方法來安裝paginate v2併爲一個集合分頁,但是我爲paginator創建的每個頁面都獲得了一個額外的「示例集合」頂級頁面鏈接。如何使用jekyll paginate v2避免使用集合的重複頁面?

下面是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個文件,我得到example.md的超過1個實例作爲我頁眉中的頁面。

如何在包含所有分頁頁面的頁眉中只有一個示例集合實例?我想我錯過了一些愚蠢的東西。

我嘗試刪除example.md YAML中的永久鏈接條目,但這樣做使得jekyll處理器無法找到examplecol/index.html。

回答

0

我花了很多試驗和錯誤,但我在頭上找到了解決方案。

當paginator製作帶有一些項目的頁面時,該站點將它們視爲頁面並呈現它們。

因此,該網站找到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> 

由於分頁程序頁面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> 
相關問題