user17833356
user17833356

Reputation:

jekyll-paginate plugin's paginate value isn't functioning

I'm trying to paginate a Jekyll-powered static blog with jekyll-paginate. I'm testing this functionality on my local machine (localhost:4000).

I've installed jekyll-paginate (1.1.0) successfully via a Gemfile. Whilst I managed to get the paginator variable (paginator.pages, paginator.total_pages, etc.) working, the paginate value that I set in _config.yml doesn't seem to be working.

I'm applying pagination to my blog list stored at /blogs/index.html. I have the following code in my config.yml file:

plugins:
- jekyll-paginate
paginate: 2
paginate_path: '/blogs/page:num/'

And I have the following code in my /blogs/index.html file: (I pretty much just copied from the official docs at https://jekyllrb.com/docs/pagination/.)

---
layout: default
title: Blogs
---
    <div style="min-height: 300px;">
        <div class="container">
                <div id="blog-post-list">
                    <div style="min-height: 300px;">
                        <div class="container">
                                    <div class="container">
                                        <div id="article-list">
                                            {% for post in paginator.posts %}
                                            <div class="article-template" style="min-height: 100px;">
                                                <!--
                                                <div id="article-media" style="background: url('https://mrlizhaozhi.github.io/archives/2021-06-06/img/the-desk.png'); height: 100px; width: 100%; background-size: cover;">
                                                </div>
                                                -->
                                                <div id="article-text">
                                                    <div class="article-info">
                                                        <div id="article-time" style="margin-bottom: 20px;">
                                                            {{ post.date | date: "%d %B %Y" }}
                                                        </div>
                                                        <div id="article-title">
                                                            <a href="{{ post.url }}">
                                                                {{ post.title }}
                                                            </a>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            {% endfor %}                           
                                        </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
        </div>
    </div>

I currently have generated four posts from .md files, so I expect to see the post list to be broken down into two pages with each having two posts listed, but this didn't happen. I suspect there's something wrong with paginate: 2 as the paginator variable is working.

I don't see what I'm getting wrong.

Upvotes: 1

Views: 122

Answers (1)

user17833356
user17833356

Reputation:

Problem solved. After research and some trials and errors, it turns out the culprit is that I didn't see the difference between jekyll serve and bundle exec jekyll serve. Whilst I used a Gemfile to bundle install the plugins, I used jekyll serve instead of bundle exec jekyll serve. After using the later command to serve the site, pagination worked great!

Upvotes: 2

Related Questions