Blog / Post

books pages story

Jekyll Paginate v2 Caching Bug Unofficial Fix

If you are looking to paginate website page content in Jekyll and want more control and features beyond the built-in Jekyll pagination you end up looking at using Jekyll::Paginate V2. Unfortunately when paginating more than one collection though things start to act bizarre. Let’s begin explaining the situation in detail.

Environment

Problem

Each collection has a directory and in each directory there is an index file (e.g. index.md). When paginate goes to build the content into pages, it checks to see if there is a cached copy of the file (e.g. index.md) and if there is one existing it will use the cached file instead. In this scenario all collections end up using the index file of the collection that was processed first. This is done due to the file name being identical.

Solution

Currently there is an issue about the caching bug, All collections using layout of first collections index found #209. Fortunately there is some great people that have created pull requests (fixes) to resolve this problem until this is officially fixed, fix jekyll 4.0 cache mismatch errors #182 and Cache mismatch Jekyll 4.0 #195 can be used instead.

Here is how you can use one of the pull request forks to resolve the problem until the official repository is fixed. Edit the “Gemfile” by changing the line gem jekyll-paginate-v2 using one of the following solutions.

mohkale / jekyll-paginate-v2

Gemfile Before

1
gem 'jekyll-paginate-v2'

Gemfile After

1
gem 'jekyll-paginate-v2', git: 'https://github.com/mohkale/jekyll-paginate-v2.git', branch: 'liquid-cache-bypass'

jameshi16 / jekyll-paginate-v2

Gemfile Before

1
gem 'jekyll-paginate-v2'

Gemfile After

1
gem 'jekyll-paginate-v2', git: 'https://github.com/jameshi16/jekyll-paginate-v2.git', branch: 'cache-mismatch-error'