diff --git a/lib/jekyll/generators/pagination.rb b/lib/jekyll/generators/pagination.rb index 70d63c88..71e27fba 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,18 @@ 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 nil if num_page.nil? || num_page <= 1 + format = site_config['paginate_path'] + format.sub(':num', num_page.to_s) + end + # Initialize a new Pager. # # config - The Hash configuration of the site. @@ -98,7 +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_path(config, @previous_page) @next_page = @page != @total_pages ? @page + 1 : nil + @next_page_path = Pager.paginate_path(config, @next_page) end # Convert this Pager's data to a Hash suitable for use by Liquid. @@ -112,7 +122,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 diff --git a/site/_posts/2012-07-01-pagination.md b/site/_posts/2012-07-01-pagination.md index b470c370..f1710d99 100644 --- a/site/_posts/2012-07-01-pagination.md +++ b/site/_posts/2012-07-01-pagination.md @@ -31,6 +31,78 @@ 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, + or nil if no previous page exists +

+

previous_page_path

+

+ path of previous pagination page, + or nil if no previous page exists +

+

next_page

+

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

+

next_page_path

+

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

+
+
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.

@@ -98,7 +170,7 @@ page with links to all but the current page. {% if paginator.previous_page == 1 %} Previous {% else %} - Previous + Previous {% endif %}

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

- Next + Next

{% else %}