/ jekyll

Upgrade to jekyll-paginate-v2

So on Jan 1st 2018, jekyll-paginate-v2 stops backward compatibility support and will break: https://travis-ci.org/ajmalafif/staging/builds/324177976#L1090

I was pulling my hair out to solve this one, but from reading through Github Issues, official documentation and some trials & error, I managed to pull it together. Here are the few files you need to change in order to get it to work again.

Paginator code snippet

This is strictly as of my setup but you can customize more, just read the documentation.

{% if paginator.total_pages > 1 %}
{{page.url}}<br>
{{page.path}}<br>

<ul class="pager">
    {% if paginator.first_page %}
    <li class="previous">
        <a href="{{ paginator.first_page_path | prepend: site.baseurl | replace: '//', '/' }}">First</a>
    </li>
    {% endif %}

    {% if paginator.previous_page %}
    <li class="previous">
        <a href="{{ paginator.previous_page_path | prepend: site.baseurl | replace: '//', '/' }}">&larr; Newer Posts</a>
    </li>
    {% endif %}

    {% if paginator.page_trail %}
      {% for trail in paginator.page_trail %}
        <li {% if page.url == trail.path %}class="selected"{% endif %}>
            <a href="{{ trail.path | prepend: site.baseurl | replace: '//', '/' }}" title="{{trail.title}}">{{ trail.num }}</a>
        </li>
      {% endfor %}
    {% endif %}

    {% if paginator.next_page %}
    <li class="next">
        <a href="{{ paginator.next_page_path | prepend: site.baseurl | replace: '//', '/' }}">Older Posts &rarr;</a>
    </li>
    {% endif %}

     {% if paginator.last_page %}
    <li class="previous">
        <a href="{{ paginator.last_page_path | prepend: site.baseurl | replace: '//', '/' }}">Last</a>
    </li>
    {% endif %}
</ul>
{% endif %}

_config.yml file

Next, again your _config.yml file, feel free to remove or add your own flavors but here’s mine as is:

pagination: enabled: true  
  permalink: '/page/:num/'  
  per_page: 5  
  trail: before: 2 # The number of links before the current page
    after: 2 
  limit: 0  
  sort_field: 'date'  
  sort_reverse: true  

This will have the URL looks like this as well: ajmalafif.com/blog/page/2/ So change accordingly if your site is not using the same format.

Your blog/page index.html page

So on the header, in between --- like this one, put in these codes to overwrite the default setting we just put in _config.yml.

pagination: enabled: true  
  trail: before: 2 
    after: 2 

Don’t ask me why, but for my setup I need at least the enabled: true else somehow it didn’t work. Feel free to go through my pains scouring through Google and Github Issues but finally, this setup works.

Hope that helps some of you (and future me for sure).