From b10939912f9c6427161d77d8553c2e0d6fcc27b0 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Tue, 9 Apr 2013 19:48:41 +0200 Subject: [PATCH 1/8] Add paginator.previous_page_path and paginator.next_page_path --- lib/jekyll/generators/pagination.rb | 38 +++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/lib/jekyll/generators/pagination.rb b/lib/jekyll/generators/pagination.rb index 70d63c88..bd797e4f 100644 --- a/lib/jekyll/generators/pagination.rb +++ b/lib/jekyll/generators/pagination.rb @@ -37,7 +37,7 @@ module Jekyll if num_page > 1 newpage = Page.new(site, site.source, page.dir, page.name) newpage.pager = pager - newpage.dir = File.join(page.dir, paginate_path(site, num_page)) + newpage.dir = File.join(page.dir, Pager.paginate_path(site.config, num_page)) site.pages << newpage else page.pager = pager @@ -45,16 +45,12 @@ module Jekyll end end - private - def paginate_path(site, num_page) - format = site.config['paginate_path'] - format.sub(':num', num_page.to_s) - end end end class Pager - attr_reader :page, :per_page, :posts, :total_posts, :total_pages, :previous_page, :next_page + attr_reader :page, :per_page, :posts, :total_posts, :total_pages, + :previous_page, :previous_page_path, :next_page, :next_page_path # Calculate the number of pages. # @@ -76,6 +72,28 @@ module Jekyll file == 'index.html' && !config['paginate'].nil? end + # Static: Return the pagination path of the page + # + # site_config - the site config + # num_page - the pagination page number + # + # Returns the pagination path as a string + def self.paginate_path(site_config, num_page) + return "/" if num_page.nil? || num_page <= 1 + format = site_config['paginate_path'] + format.sub(':num', num_page.to_s) + end + + def self.paginate_url(site_config, num_page) + return "" if num_page.nil? + path = paginate_path(site_config, num_page) + if path[0..1] == "/" + path + else + "/#{path}" + end + end + # Initialize a new Pager. # # config - The Hash configuration of the site. @@ -98,7 +116,9 @@ module Jekyll @total_posts = all_posts.size @posts = all_posts[init..offset] @previous_page = @page != 1 ? @page - 1 : nil + @previous_page_path = Pager.paginate_url(config, @previous_page) @next_page = @page != @total_pages ? @page + 1 : nil + @next_page_path = Pager.paginate_url(config, @next_page) end # Convert this Pager's data to a Hash suitable for use by Liquid. @@ -112,7 +132,9 @@ module Jekyll 'total_posts' => total_posts, 'total_pages' => total_pages, 'previous_page' => previous_page, - 'next_page' => next_page + 'previous_page_path' => previous_page_path, + 'next_page' => next_page, + 'next_page_path' => next_page_path } end end From c0f50f2c7876741bbc419d07eaf12f1ef5d1c6c4 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Tue, 9 Apr 2013 19:51:26 +0200 Subject: [PATCH 2/8] Update docs to use paginator.{next,previous}_page_path --- site/_posts/2012-07-01-pagination.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site/_posts/2012-07-01-pagination.md b/site/_posts/2012-07-01-pagination.md index b470c370..8f3f7b4d 100644 --- a/site/_posts/2012-07-01-pagination.md +++ b/site/_posts/2012-07-01-pagination.md @@ -98,7 +98,7 @@ page with links to all but the current page. {% if paginator.previous_page == 1 %} Previous {% else %} - Previous + Previous {% endif %}

{% else %} @@ -129,7 +129,7 @@ page with links to all but the current page. {% if paginator.next_page %}

- Next + Next

{% else %}

From 102e29899fd1a58de5d82759bd3a1d7b6794c0a8 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Tue, 9 Apr 2013 20:11:12 +0200 Subject: [PATCH 3/8] Add some docs regarding what the paginator exposes in liquid --- site/_posts/2012-07-01-pagination.md | 52 ++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/site/_posts/2012-07-01-pagination.md b/site/_posts/2012-07-01-pagination.md index 8f3f7b4d..e412e697 100644 --- a/site/_posts/2012-07-01-pagination.md +++ b/site/_posts/2012-07-01-pagination.md @@ -31,6 +31,58 @@ paginate: 5 The number should be the maximum number of Posts you’d like to be displayed per- page in the generated site. +## Liquid Attributes Available + +The pagination plugin exposes the `paginator` liquid object with the following +attributes: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
AttributeDescription

page

current page number

per_page

number of posts per page

posts

a list of posts for the current page

total_posts

total number of posts in the site

total_pages

number of pagination pages

previous_page

page number of the previous pagination page

previous_page_path

path (including leading "/") of previous pagination page

next_page

page number of the next pagination page

next_page_path

path (including leading "/") of next pagination page

+

Pagination does not support tags or categories

Pagination pages through every post in the posts variable regardless of variables defined in the YAML Front Matter of each. It does not currently allow paging over groups of posts linked by a common tag or category.

From e5bf5aa09e1ec5d554661ee1a7066abc276bdc93 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Tue, 9 Apr 2013 20:25:33 +0200 Subject: [PATCH 4/8] Documentation for Pager.paginate_url --- lib/jekyll/generators/pagination.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/jekyll/generators/pagination.rb b/lib/jekyll/generators/pagination.rb index bd797e4f..1a239ce9 100644 --- a/lib/jekyll/generators/pagination.rb +++ b/lib/jekyll/generators/pagination.rb @@ -84,6 +84,12 @@ module Jekyll format.sub(':num', num_page.to_s) end + # Static: Return the URL for the pagination path of the page + # + # site_config - the site config + # num_page - the pagination page number + # + # Returns the the absolute URL for the pagination page def self.paginate_url(site_config, num_page) return "" if num_page.nil? path = paginate_path(site_config, num_page) From b9e7a31ab876c37527a9d8ac5c8fa506ffa9274d Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Tue, 9 Apr 2013 20:25:43 +0200 Subject: [PATCH 5/8] Return nil if num_page is nil --- lib/jekyll/generators/pagination.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/generators/pagination.rb b/lib/jekyll/generators/pagination.rb index 1a239ce9..ca5eb9ed 100644 --- a/lib/jekyll/generators/pagination.rb +++ b/lib/jekyll/generators/pagination.rb @@ -91,7 +91,7 @@ module Jekyll # # Returns the the absolute URL for the pagination page def self.paginate_url(site_config, num_page) - return "" if num_page.nil? + return nil if num_page.nil? path = paginate_path(site_config, num_page) if path[0..1] == "/" path From 9c296f04a9b8823d05a119f39629c1488b4651d0 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Tue, 9 Apr 2013 20:26:08 +0200 Subject: [PATCH 6/8] Join the path with baseurl in Pager.paginate_url --- lib/jekyll/generators/pagination.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/jekyll/generators/pagination.rb b/lib/jekyll/generators/pagination.rb index ca5eb9ed..59a0d539 100644 --- a/lib/jekyll/generators/pagination.rb +++ b/lib/jekyll/generators/pagination.rb @@ -93,11 +93,7 @@ module Jekyll def self.paginate_url(site_config, num_page) return nil if num_page.nil? path = paginate_path(site_config, num_page) - if path[0..1] == "/" - path - else - "/#{path}" - end + File.join(site_config["baseurl"], path) end # Initialize a new Pager. From c9a8a1b29f060445284e07df2f4dbaabe18e3d21 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Tue, 9 Apr 2013 20:29:48 +0200 Subject: [PATCH 7/8] A bunch of pagination attributes will be nil if the subsequent/previous pages don't exist --- site/_posts/2012-07-01-pagination.md | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/site/_posts/2012-07-01-pagination.md b/site/_posts/2012-07-01-pagination.md index e412e697..4706a2cc 100644 --- a/site/_posts/2012-07-01-pagination.md +++ b/site/_posts/2012-07-01-pagination.md @@ -66,19 +66,39 @@ attributes:

previous_page

-

page number of the previous pagination page

+ +

+ page number of the previous pagination page, + or nil if no previous page exists +

+

previous_page_path

-

path (including leading "/") of previous pagination page

+ +

+ path (including leading "/") of previous pagination page, + or nil if no previous page exists +

+

next_page

-

page number of the next pagination page

+ +

+ page number of the next pagination page, + or nil if no subsequent page exists +

+

next_page_path

-

path (including leading "/") of next pagination page

+ +

+ path (including leading "/") of next pagination page, + or nil if no subsequent page exists +

+ From 88f92729bc2fa30cf8ab7d842d4f7a4f30fd8c76 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Tue, 9 Apr 2013 21:00:27 +0200 Subject: [PATCH 8/8] Use paginate_path and don't help too much --- lib/jekyll/generators/pagination.rb | 18 +++--------------- site/_posts/2012-07-01-pagination.md | 4 ++-- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/lib/jekyll/generators/pagination.rb b/lib/jekyll/generators/pagination.rb index 59a0d539..71e27fba 100644 --- a/lib/jekyll/generators/pagination.rb +++ b/lib/jekyll/generators/pagination.rb @@ -79,23 +79,11 @@ module Jekyll # # Returns the pagination path as a string def self.paginate_path(site_config, num_page) - return "/" if num_page.nil? || num_page <= 1 + return nil if num_page.nil? || num_page <= 1 format = site_config['paginate_path'] format.sub(':num', num_page.to_s) end - # Static: Return the URL for the pagination path of the page - # - # site_config - the site config - # num_page - the pagination page number - # - # Returns the the absolute URL for the pagination page - def self.paginate_url(site_config, num_page) - return nil if num_page.nil? - path = paginate_path(site_config, num_page) - File.join(site_config["baseurl"], path) - end - # Initialize a new Pager. # # config - The Hash configuration of the site. @@ -118,9 +106,9 @@ module Jekyll @total_posts = all_posts.size @posts = all_posts[init..offset] @previous_page = @page != 1 ? @page - 1 : nil - @previous_page_path = Pager.paginate_url(config, @previous_page) + @previous_page_path = Pager.paginate_path(config, @previous_page) @next_page = @page != @total_pages ? @page + 1 : nil - @next_page_path = Pager.paginate_url(config, @next_page) + @next_page_path = Pager.paginate_path(config, @next_page) end # Convert this Pager's data to a Hash suitable for use by Liquid. diff --git a/site/_posts/2012-07-01-pagination.md b/site/_posts/2012-07-01-pagination.md index 4706a2cc..f1710d99 100644 --- a/site/_posts/2012-07-01-pagination.md +++ b/site/_posts/2012-07-01-pagination.md @@ -77,7 +77,7 @@ attributes:

previous_page_path

- path (including leading "/") of previous pagination page, + path of previous pagination page, or nil if no previous page exists

@@ -95,7 +95,7 @@ attributes:

next_page_path

- path (including leading "/") of next pagination page, + path of next pagination page, or nil if no subsequent page exists