From d218c99fa6daf033184855f5df6fb4d750e3409e Mon Sep 17 00:00:00 2001 From: Pixelastic Date: Mon, 14 May 2018 18:08:32 +0200 Subject: [PATCH] fix(jekyll-paginate): Less hackish way of disabling jekyll-paginate --- lib/jekyll-algolia.rb | 1 + lib/jekyll/algolia/configurator.rb | 6 ------ .../overwrites/jekyll-paginate-pager.rb | 20 +++++++++++++++++++ spec/integration/main_spec.rb | 7 ++++--- spec/integration/site/_config.yml | 2 +- .../site/_posts/2018-05-13-post1.md | 5 +++++ .../site/_posts/2018-05-14-post2.md | 5 +++++ spec/integration/site/index.html | 10 ++++++---- spec/jekyll/algolia/configurator_spec.rb | 4 ---- 9 files changed, 42 insertions(+), 18 deletions(-) create mode 100644 lib/jekyll/algolia/overwrites/jekyll-paginate-pager.rb create mode 100644 spec/integration/site/_posts/2018-05-13-post1.md create mode 100644 spec/integration/site/_posts/2018-05-14-post2.md diff --git a/lib/jekyll-algolia.rb b/lib/jekyll-algolia.rb index 392a503..4e21382 100644 --- a/lib/jekyll-algolia.rb +++ b/lib/jekyll-algolia.rb @@ -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 diff --git a/lib/jekyll/algolia/configurator.rb b/lib/jekyll/algolia/configurator.rb index f7adc17..b061ede 100644 --- a/lib/jekyll/algolia/configurator.rb +++ b/lib/jekyll/algolia/configurator.rb @@ -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 diff --git a/lib/jekyll/algolia/overwrites/jekyll-paginate-pager.rb b/lib/jekyll/algolia/overwrites/jekyll-paginate-pager.rb new file mode 100644 index 0000000..b129e9d --- /dev/null +++ b/lib/jekyll/algolia/overwrites/jekyll-paginate-pager.rb @@ -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 diff --git a/spec/integration/main_spec.rb b/spec/integration/main_spec.rb index d21931c..8cd00d8 100644 --- a/spec/integration/main_spec.rb +++ b/spec/integration/main_spec.rb @@ -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 diff --git a/spec/integration/site/_config.yml b/spec/integration/site/_config.yml index c2265c2..65a71e4 100644 --- a/spec/integration/site/_config.yml +++ b/spec/integration/site/_config.yml @@ -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 diff --git a/spec/integration/site/_posts/2018-05-13-post1.md b/spec/integration/site/_posts/2018-05-13-post1.md new file mode 100644 index 0000000..db88e4d --- /dev/null +++ b/spec/integration/site/_posts/2018-05-13-post1.md @@ -0,0 +1,5 @@ +--- +title: Post 1 +--- + +This is just another dummy post to force some pagination diff --git a/spec/integration/site/_posts/2018-05-14-post2.md b/spec/integration/site/_posts/2018-05-14-post2.md new file mode 100644 index 0000000..b6da6fa --- /dev/null +++ b/spec/integration/site/_posts/2018-05-14-post2.md @@ -0,0 +1,5 @@ +--- +title: Post 2 +--- + +This is just a dummy post to force some pagination diff --git a/spec/integration/site/index.html b/spec/integration/site/index.html index 8109d6b..d7e285d 100644 --- a/spec/integration/site/index.html +++ b/spec/integration/site/index.html @@ -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 %} - - {{ post.title }} - - {{ post.content }} +

+ + {{ post.title }} + +

+

{{ post.content }}

{% endfor %} diff --git a/spec/jekyll/algolia/configurator_spec.rb b/spec/jekyll/algolia/configurator_spec.rb index aa45f53..d7d96ef 100644 --- a/spec/jekyll/algolia/configurator_spec.rb +++ b/spec/jekyll/algolia/configurator_spec.rb @@ -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