From ea71036e8ccc20b42037a07f307adcdb469a34c9 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 5 May 2013 15:40:13 +0200 Subject: [PATCH 1/6] Paginate in subdirectories properly. Fixes #878. --- lib/jekyll/generators/pagination.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/jekyll/generators/pagination.rb b/lib/jekyll/generators/pagination.rb index 71e27fba..a0e8b819 100644 --- a/lib/jekyll/generators/pagination.rb +++ b/lib/jekyll/generators/pagination.rb @@ -11,7 +11,7 @@ module Jekyll # Returns nothing. def generate(site) site.pages.dup.each do |page| - paginate(site, page) if Pager.pagination_enabled?(site.config, page.name) + paginate(site, page) if Pager.pagination_enabled?(site.config, page) end end @@ -65,11 +65,13 @@ module Jekyll # Determine if pagination is enabled for a given file. # # config - The configuration Hash. - # file - The String filename of the file. + # page - The Jekyll::Page with which to paginate # # Returns true if pagination is enabled, false otherwise. - def self.pagination_enabled?(config, file) - file == 'index.html' && !config['paginate'].nil? + def self.pagination_enabled?(config, page) + page.name == 'index.html' && + !config['paginate'].nil? && + File.dirname(config['paginate_path']) == page.dir end # Static: Return the pagination path of the page @@ -80,7 +82,7 @@ module Jekyll # Returns the pagination path as a string def self.paginate_path(site_config, num_page) return nil if num_page.nil? || num_page <= 1 - format = site_config['paginate_path'] + format = File.basename(site_config['paginate_path']) format.sub(':num', num_page.to_s) end From 5836b441f6e412272839c3a9c0801ebdec4d798f Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 5 May 2013 17:25:09 +0200 Subject: [PATCH 2/6] Fixing up pagination feature test --- features/pagination.feature | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/features/pagination.feature b/features/pagination.feature index cc3cf4d6..9482f18f 100644 --- a/features/pagination.feature +++ b/features/pagination.feature @@ -2,13 +2,13 @@ Feature: Site pagination In order to paginate my blog As a blog's user I want divide the posts in several pages - + Scenario Outline: Paginate with N posts per page Given I have a configuration file with "paginate" set to "" And I have a _layouts directory And I have an "index.html" page that contains "{{ paginator.posts.size }}" And I have a _posts directory - And I have the following post: + And I have the following posts: | title | date | layout | content | | Wargames | 3/27/2009 | default | The only winning move is not to play. | | Wargames2 | 4/27/2009 | default | The only winning move is not to play2. | @@ -32,10 +32,10 @@ Feature: Site pagination | paginate | 1 | | paginate_path | /blog/page-:num | | permalink | /blog/:year/:month/:day/:title | - And I have a _layouts directory - And I have an "index.html" page that contains "{{ paginator.posts.size }}" + And I have a blog directory + And I have an "blog/index.html" page that contains "{{ paginator.posts.size }}" And I have a _posts directory - And I have the following post: + And I have the following posts: | title | date | layout | content | | Wargames | 3/27/2009 | default | The only winning move is not to play. | | Wargames2 | 4/27/2009 | default | The only winning move is not to play2. | From 2d0e65b5f798ea3685d31250f4a4c0f74bdc8486 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 5 May 2013 17:25:42 +0200 Subject: [PATCH 3/6] In Cucumber step definitions, it'd be smart not to chdir into a dir we're about to kill --- features/step_definitions/jekyll_steps.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index c30b9034..75330738 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -5,7 +5,7 @@ Before do end After do - Dir.chdir(TEST_DIR) + Dir.chdir(File.expand_path("..", TEST_DIR)) FileUtils.rm_rf(TEST_DIR) end From 050e982006feaad46ddc83743ca06287957c5a64 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 5 May 2013 17:26:29 +0200 Subject: [PATCH 4/6] Add extra question to ensure that the index.html file is in thepagination path's directory --- lib/jekyll/generators/pagination.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/jekyll/generators/pagination.rb b/lib/jekyll/generators/pagination.rb index a0e8b819..0cd934c5 100644 --- a/lib/jekyll/generators/pagination.rb +++ b/lib/jekyll/generators/pagination.rb @@ -69,9 +69,19 @@ module Jekyll # # Returns true if pagination is enabled, false otherwise. def self.pagination_enabled?(config, page) - page.name == 'index.html' && - !config['paginate'].nil? && - File.dirname(config['paginate_path']) == page.dir + !config['paginate'].nil? && + page.name == 'index.html' && + subdirectories_identical(config['paginate_path'], page.dir) + end + + # Determine if the subdirectories of the two paths are the same relative to source + # + # paginate_path - the paginate_path configuration setting + # page_dir - the directory of the Jekyll::Page + # + # Returns whether the subdirectories are the same relative to source + def self.subdirectories_identical(paginate_path, page_dir) + File.dirname(paginate_path).gsub(/\A\./, '') == page_dir.gsub(/\/\z/, '') end # Static: Return the pagination path of the page From 1c146ec649aebb55ce8c2259fc8b00a8426e3d63 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 5 May 2013 17:26:48 +0200 Subject: [PATCH 5/6] Instead of just a string name, Pager.pagination_enabled? now accepts a page --- test/test_pager.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_pager.rb b/test/test_pager.rb index fe1156ca..afdf4a2b 100644 --- a/test/test_pager.rb +++ b/test/test_pager.rb @@ -23,7 +23,7 @@ class TestPager < Test::Unit::TestCase end should "report that pagination is disabled" do - assert !Pager.pagination_enabled?(@config, 'index.html') + assert !Pager.pagination_enabled?(@config, OpenStruct.new(name: 'index.html', dir: '/')) end end @@ -45,7 +45,7 @@ class TestPager < Test::Unit::TestCase end should "report that pagination is enabled" do - assert Pager.pagination_enabled?(@config, 'index.html') + assert Pager.pagination_enabled?(@config, OpenStruct.new(name: 'index.html', dir: '/')) end context "with 4 posts" do From dcd7b362697f896df2f6d69735a045c07dd9b89e Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 5 May 2013 18:08:03 +0200 Subject: [PATCH 6/6] Fixing Pager test for 1.8.7. --- test/helper.rb | 1 + test/test_pager.rb | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/test/helper.rb b/test/helper.rb index a20d236f..3ee3f2b6 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -6,6 +6,7 @@ end require 'rubygems' require 'test/unit' +require 'ostruct' gem 'RedCloth', '>= 4.2.1' require 'jekyll' diff --git a/test/test_pager.rb b/test/test_pager.rb index afdf4a2b..7e153ea4 100644 --- a/test/test_pager.rb +++ b/test/test_pager.rb @@ -23,7 +23,8 @@ class TestPager < Test::Unit::TestCase end should "report that pagination is disabled" do - assert !Pager.pagination_enabled?(@config, OpenStruct.new(name: 'index.html', dir: '/')) + page = OpenStruct.new({ :name => 'index.html', :dir => '/' }) + assert !Pager.pagination_enabled?(@config, page) end end @@ -45,7 +46,8 @@ class TestPager < Test::Unit::TestCase end should "report that pagination is enabled" do - assert Pager.pagination_enabled?(@config, OpenStruct.new(name: 'index.html', dir: '/')) + page = OpenStruct.new({ :name => 'index.html', :dir => '/' }) + assert Pager.pagination_enabled?(@config, page) end context "with 4 posts" do