【问题标题】:Issue building Jekyll blog post page and pagenation问题构建 Jekyll 博客文章页面和分页
【发布时间】:2013-11-15 06:34:28
【问题描述】:

今晚我为my website 添加了分页,但我遇到了问题,现在我已经破坏了我的整个网站。

我对文件使用标准的 Jekyll 目录结构。对于我的网站,我希望索引页面是关于我的,然后单击/blog 页面查看我的博客。所以我有 index.md 在主页上。然后我有一个页面 blog.html 是博客页面。我曾经使用{% for post in site.posts limit: 10 %},它工作并切换到{% for post in paginator.posts %},基于最新文档如何推荐循环并且它打破了。在我的 _config.yml 文件中,我有:

paginate: 10
paginate_path: "blog/page:num"
permalink: /blog/:year/:month/:day/:title.html

我希望分页是 /blog/page2.html。我不确定我配置错了什么。这是我的整个 blog.html 页面:

---
title: Blog
layout: default
permalink: /blog/index.html
---

{% for post in paginator.posts %}
<div class="row">
    <div class="col-lg-12">
        {% if post.layout contains "link" %}
        <h4><a href="{{post.url}}"><i class="icon-link"></i>&nbsp;{{post.title}}</a></h4>
        {% else %}
        <h4><a href="{{post.url}}">{{post.title}}</a></h4>
        {% endif %}
        <small>{{post.date | date: "%m/%d/%Y"}}</small>
        <div class="post-content-truncate">
            {% if post.content contains "<!-- more -->" %}
                {{ post.content | split:"<!-- more -->" | first % }}
                <a href="{{post.url}}">Read full article...</a>
            {% else %}
                {{ post.content }}
            {% endif %}
        </div>
    </div>
</div>
{% endfor %}

{% if paginator.total_pages > 1 %}
<div class="row">
    <div class="col-lg-12">
            <ul class="pagination">
                {% if paginator.previous_page %}
                    <li><a href="{{ paginator.previous_page_path | prepend: site.baseurl | replace: '//', '/' }}">&laquo; Prev</a></li>
                {% else %}
                    <span>&laquo; Prev</span>
                {% endif %}

                {% for page in (1..paginator.total_pages) %}
                    {% if page == paginator.page %}
                        <li><em>{{ page }}</em></li>
                    {% elsif page == 1 %}
                        <li><a href="{{ '/index.html' | prepend: site.baseurl | replace: '//', '/' }}">{{ page }}</a></li>
                    {% else %}
                        <li><a href="{{ site.paginate_path | prepend: site.baseurl | replace: '//', '/' | replace: ':num', page }}">{{ page }}</a></li>
                    {% endif %}
                {% endfor %}

                {% if paginator.next_page %}
                    <li><a href="{{ paginator.next_page_path | prepend: site.baseurl | replace: '//', '/' }}">Next &raquo;</a></li>
                {% else %}
                    <li><span>Next &raquo;</span></li>
                {% endif %}
            </ul>
    </div>
</div>
{% endif %}

对我哪里出错有任何想法吗?

【问题讨论】:

    标签: templates pagination jekyll


    【解决方案1】:

    问题其实是两个问题:

    1. 我使用的是旧版本的 Jekyll。升级到最新版本后,它几乎可以正常工作了。
    2. 我必须将 /blog.html 文件放入 /blog/index.html

    一旦我完成了这两个步骤,它就起作用了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多