fix(jekyll-paginate): Less hackish way of disabling jekyll-paginate

This commit is contained in:
Pixelastic 2018-05-14 18:08:32 +02:00
parent e18794eb25
commit d218c99fa6
9 changed files with 42 additions and 18 deletions

View File

@ -55,6 +55,7 @@ module Jekyll
require 'jekyll/algolia/overwrites/githubpages-configuration'
require 'jekyll/algolia/overwrites/jekyll-algolia-site'
require 'jekyll/algolia/overwrites/jekyll-document'
require 'jekyll/algolia/overwrites/jekyll-paginate-pager'
require 'jekyll/algolia/overwrites/jekyll-tags-link'
# Register our own tags to overwrite the default tags

View File

@ -234,12 +234,6 @@ module Jekyll
# Public: Disable features from other Jekyll plugins that might interfere
# with the indexing
def self.disable_other_plugins(config)
# Disable pagination from jekyll-paginate
# It creates a lot of /page2/index.html files that are not relevant to
# indexing
# https://github.com/jekyll/jekyll-paginate/blob/master/lib/jekyll-paginate/pager.rb#L23
config['paginate'] = nil
# Disable archive pages from jekyll-archives
config['jekyll-archives'] = nil

View File

@ -0,0 +1,20 @@
# frozen_string_literal: true
module Jekyll
module Paginate
# Disable pagination from jekyll-paginate
#
# This plugin will create pages that contain a list of all items to
# paginate. Those pages won't contain any interesting data to be indexed
# (as it will be duplicated content of the real pages), but will still
# take time to generate.
#
# By monkey-patching the plugin, we force it to be disabled
# https://github.com/jekyll/jekyll-paginate/blob/master/lib/jekyll-paginate/pager.rb#L22
class Pager
def self.pagination_enabled?(_site)
false
end
end
end
end

View File

@ -12,6 +12,7 @@ describe('pushed index') do
# Files excluded from indexing should still be written on disk
it { should have_file('404.html') }
it { should have_file('index.html') }
it { should have_file('blog/pages/2/index.html') }
end
# Custom hooks are executed, even if github-pages is added as a gem
@ -58,15 +59,15 @@ describe('pushed index') do
context 'by default' do
let(:distinct) { nil }
it { should eq 5 }
it { should eq 7 }
end
context 'with distinct:true' do
let(:distinct) { true }
it { should eq 5 }
it { should eq 7 }
end
context 'with distinct:false' do
let(:distinct) { false }
it { should eq 9 }
it { should eq 11 }
end
end
end

View File

@ -17,7 +17,7 @@ algolia:
separatorsToIndex: '∀λ→'
# jekyll-paginate lets you define the path to the pagination pages
paginate: 5
paginate: 2
paginate_path: "/blog/pages/:num"
# jekyll-tagging lets you define where to save the tag files

View File

@ -0,0 +1,5 @@
---
title: Post 1
---
This is just another dummy post to force some pagination

View File

@ -0,0 +1,5 @@
---
title: Post 2
---
This is just a dummy post to force some pagination

View File

@ -8,9 +8,11 @@ This default index page is usually used to display the list of posts, or briefly
I feel that it should not be indexed.
{% for post in paginator.posts %}
<a href="{{ site.baseurl }}{{ post.url }}">
{{ post.title }}
</a>
{{ post.content }}
<h2>
<a href="{{ site.baseurl }}{{ post.url }}">
{{ post.title }}
</a>
</h2>
<p>{{ post.content }}</p>
{% endfor %}

View File

@ -411,10 +411,6 @@ describe(Jekyll::Algolia::Configurator) do
describe '.disable_other_plugins' do
subject { current.disable_other_plugins(config) }
context 'disable jekyll-paginate' do
it { should include('paginate' => nil) }
end
context 'disable jekyll-archives' do
it { should include('jekyll-archives' => nil) }
end