1
votes

I was adding pagination to my website tonight and I ran into issues where now I have broke my whole site.

I am using the standard Jekyll directory structure for the files. For my website, I want the index page to be about me, then you click the /blog page to view my blog. So I have index.md be by main page. Then I have a page blog.html be the blog page. I used to use {% for post in site.posts limit: 10 %} which worked and switched to {% for post in paginator.posts %} based on how the latest documentation recommended the loop and it broke. In my _config.yml file I have:

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

I want the paging to be /blog/page2.html. I am unsure what I have configured wrong. Here is my entire blog.html page:

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

Any ideas of where I am going wrong?

1

1 Answers

2
votes

The problem was actually two problems:

  1. I was using an older version of Jekyll. Once I upgraded to the latest it was almost working.
  2. I had to put my /blog.html file into /blog/index.html

Once I did those two steps it worked.