【问题标题】:Is there a way to set up pagination for Collections in a Jekyll site?有没有办法在 Jekyll 站点中为集合设置分页?
【发布时间】:2015-12-03 01:49:51
【问题描述】:

根据 Jekyll 的文档,不支持对集合进行分页。我尝试为我的投资组合集合模仿 Jekyll 帖子文件夹结构,然后应用稍微修改的分页 Liquid 语法来处理投资组合集合,但无济于事。

有没有一种方法/解决方法可以在 Jekyll 网站中为集合设置分页?

【问题讨论】:

    标签: github pagination jekyll github-pages


    【解决方案1】:

    有一种方法可以将 prev 和 next 标签分配给您的收藏的“假”分页。以下是 anjesh 的做法:

    {% for c in site.tripcollection %}
    {% if c.title == page.title %}
      {% assign thisPost = c %}
      {% if forloop.index == 1 %}
        {% assign prevflag = 0 %}
        {% assign nextflag = 1 %}
      {% elsif forloop.index == forloop.length %}
        {% assign prevflag = 1 %}
        {% assign nextflag = 0 %}
      {% else %}
        {% assign prevflag = 1 %}
        {% assign nextflag = 1 %}
      {% endif %}  
    {% endif %}
    {% endfor %}
    
    {% for c in site.tripcollection %}
      {% if c.title == page.title %}
        {% assign prevflag = 0 %}
      {% endif %}
      {% if prevflag == 1 %}
        {% assign prevPost = c %}
        {% assign page.previous = c %}
      {% endif %}
    {% endfor %}
    
    {% if nextflag == 1 %}
      {% for c in site.tripcollection %}
        {% if foundPost == 1 %}
          {% assign getNext = 1 %}
        {% endif %}
        {% if c.title == page.title %}
          {% assign foundPost = 1 %}        
        {% endif %}
        {% if getNext == 1%}
          {% assign nextPost = c %}
          {% assign page.next = c %}
          {% assign foundPost = 0 %}
          {% assign getNext = 0 %}
        {% endif %}
      {% endfor %}
    {% endif %}
    
    <div id="post-nav">
        <div >    
            {% if prevPost.url %}
            <a class="prev" href="{{prevPost.url}}">
                <span>&lt; {{prevPost.title}}</span>
            </a> 
            {% endif %} 
            {% if nextPost.url %} 
            <a class="next" href="{{nextPost.url}}">
                <span>{{nextPost.title}} &gt;</span>
            </a> 
            {% endif %} 
        </div>
    </div>
    

    你可以在这里阅读他的整个帖子:Get Pagination working in Jekyll Collection in Github pages

    【讨论】:

    • 这看起来与分页无关:相反,它看起来像是在为集合中的各个帖子添加下一个/上一个链接。
    【解决方案2】:

    jekyll-paginate 仅对帖子进行分页。

    如果要对集合进行分页,可以使用Octopress Paginate,但 github 不支持 (for now)。

    【讨论】:

    • 当然。谢谢你说清楚。我遇到过 Octopress Paginate,但只要我正在构建一个完全由 github 页面支持的 jekyll 站点(没有任何插件依赖项),我希望有一个纯 Liquid 语法解决方法,也许在一些 js 函数的帮助下或jQuery 插件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多