jekyllgithub-pagesjekyll-paginator

Paginate with GH Pages's default plugins?


I'm trying to populate my small blog on GH Pages. I'm stuck at Jekyll paginating.

Here's my _config.yml:

theme: jekyll-theme-cayman

title: iBug @ GitHub
url: https://ibug.github.io/
tagline: The small personal site for iBug
description: The small personal site for iBug
author: iBug
show_downloads: false

plugins:
  - jekyll-paginate
  - jekyll-redirect-from
  - jekyll-mentions
  - jekyll-seo-tag

paginate: 5
paginate_path: "/blog/page:num/"

And here's the content of the only post there:

---
layout: blog
permalink: /p/1
---

# Test Post

Nothing here

I want a paginated index page on /blog, and succeeding pages on /blog/page# (where # is a number). I copied a sample index.html and placed it at /blog/index.html in my repo.

But when I navigate to https://ibug.github.io/blog , it just show up like this:

{% if paginator.total_pages > 1 %} {% if paginator.previous_page %} « Prev {% else %} « Prev {% endif %} {% for page in (1..paginator.total_pages) %} {% if page == paginator.page %} {{ page }} {% elsif page == 1 %} {{ page }} {% else %} {{ page }} {% endif %} {% endfor %} {% if paginator.next_page %} Next » {% else %} Next » {% endif %} {% endif %}

Reading the GH documentation, I learned that jekyll-paginate is a default plugin and cannot be disabled, so it shouldn't work this way.

I also have a dummy post at /_posts/2018-03-01-first-post.md, and it correctly shows up at https://ibug.github.io/2018/03/01/first-post

I don't want to install a Ruby dev environment and other stuff. I want to use only GH Pages's builtin functionality.

Can I get an index at /blog and /blog/pageN?


Solution

  • Looking at your source code, this likely is an issue with the index.html file within your blog subdirectory.

    You need to include front matter, even if it contains no key/value data, within any file you want processed by Jekyll. Without this, Jekyll assumes that it's a static asset and will just copy it over directly into your _site directory upon build.

    Adding this at the top of your index.html file should fix it:

    ---
    ---
    content here
    

    You'll also want to be sure you're actually showing posts on that page and not just the pagination navigation. So be sure to include something like this above it:

    {% for post in paginator.posts %}
      <h1><a href="{{ post.url }}">{{ post.title }}</a></h1>
      <p class="author">
        <span class="date">{{ post.date }}</span>
      </p>
      <div class="content">
        {{ post.content }}
      </div>
    {% endfor %}
    

    As a side note, you may want to look into setting defaults within your _config.yml for post permalinks. It can be a lot cleaner than defining the link on every post.