diff --git a/README-AUTOPAGES.md b/README-AUTOPAGES.md index 4e24e15..ab52fec 100644 --- a/README-AUTOPAGES.md +++ b/README-AUTOPAGES.md @@ -10,9 +10,12 @@ > This feature is based on [code](https://github.com/stevecrozz/lithostech.com/blob/master/_plugins/tag_indexes.rb) written and graciously donated by [Stephen Crosby](https://github.com/stevecrozz). Thanks! :) * [Site configuration](#site-configuration) +* [Simple configuration](#simple-configuration) + + [Obtaining the original Tag or Category name](#obtaining-the-original-tag-or-category-name) * [Advanced configuration](#advanced-configuration) * [Specialised pages](#specialised-pages) * [Considerations](#considerations) + + [Title should not contain pagination macros](#title-should-not-contain-pagination-macros) * [Example Sites](https://github.com/sverrirs/jekyll-paginate-v2/tree/master/examples) * [Common issues](#common-issues) diff --git a/README-GENERATOR.md b/README-GENERATOR.md index aabff84..72773d5 100644 --- a/README-GENERATOR.md +++ b/README-GENERATOR.md @@ -25,6 +25,7 @@ The **Generator** forms the core of the pagination logic. It is responsible for * [Creating Pagination Trails](#creating-pagination-trails) * [How to detect auto-generated pages](#detecting-generated-pagination-pages) * [Formatting page titles](#formatting-page-titles) +* [Reading pagination meta information](#reading-pagination-meta-information) * [Common issues](#common-issues) - [Dependency Error after installing](#i-keep-getting-a-dependency-error-when-running-jekyll-serve-after-installing-this-gem) - [Bundler error upgrading gem (Bundler::GemNotFound)](#im-getting-a-bundler-error-after-upgrading-the-gem-bundlergemnotfound) @@ -441,6 +442,21 @@ The `title` field in both the site.config and the front-matter configuration sup | :num | number of the current page | Page with `title: "Index"` and paginate config `title: ":title (page :num)"` the second page becomes `Index (page 2)` | | :max | total number of pages | Page with paginate config `title: ":num of :max"` the third page of 10 will become `3 of 10"` | +## Reading pagination meta information +Each pagination page defines an information structure `pagination_info` that is available to the liquid templates. This structure contains meta information for the pagination process, such as current pagination page and the total number of paginated pages. + +The following fields are available +| Field | Description | +| --- | --- | +| curr_page | The number of the current pagination page | +| total_pages | The total number of pages in this pagination | + +Below is an example on how to print out a "Page x of n" in the pagination layout + +``` html +

Page {{page.pagination_info.curr_page}} of {{page.pagination_info.total_pages}}

+``` + ## Common issues ### I keep getting a dependency error when running jekyll serve after installing this gem diff --git a/examples/03-tags/_layouts/autopage_cat.html b/examples/03-tags/_layouts/autopage_cat.html index 745e647..4ec577e 100644 --- a/examples/03-tags/_layouts/autopage_cat.html +++ b/examples/03-tags/_layouts/autopage_cat.html @@ -9,7 +9,7 @@
-

AutoPage Category {% if page.autopages %}{{page.autopage.display_name}}{% endif %}

+

AutoPage Category {% if page.autopages %}{{page.autopage.display_name}}{% endif %} Page {{page.pagination_info.curr_page}} of {{page.pagination_info.total_pages}}

Omg! all the categories in one paginated place diff --git a/examples/03-tags/_layouts/autopage_collection.html b/examples/03-tags/_layouts/autopage_collection.html index a6a56ad..cd43e0d 100644 --- a/examples/03-tags/_layouts/autopage_collection.html +++ b/examples/03-tags/_layouts/autopage_collection.html @@ -9,7 +9,7 @@
-

AutoPage Collection {% if page.autopages %}{{page.autopages.display_name}}{% endif %}

+

AutoPage Collection {% if page.autopages %}{{page.autopages.display_name}}{% endif %} Page {{page.pagination_info.curr_page}} of {{page.pagination_info.total_pages}}

AUTO CREATED FOR ALL COLLECTIONS IN THE SITE diff --git a/examples/03-tags/_layouts/autopage_collections_tags.html b/examples/03-tags/_layouts/autopage_collections_tags.html index 561e1b1..950beaa 100644 --- a/examples/03-tags/_layouts/autopage_collections_tags.html +++ b/examples/03-tags/_layouts/autopage_collections_tags.html @@ -15,7 +15,7 @@
-

AutoPage Collection ALL : Tag {% if page.autopages %}{{page.autopages.display_name}}{% endif %}

+

AutoPage Collection ALL : Tag {% if page.autopages %}{{page.autopages.display_name}}{% endif %} Page {{page.pagination_info.curr_page}} of {{page.pagination_info.total_pages}}

This page is automagically created and paginated for each tag available in the posts on this site diff --git a/examples/03-tags/_layouts/autopage_tags.html b/examples/03-tags/_layouts/autopage_tags.html index 8684e35..020fd21 100644 --- a/examples/03-tags/_layouts/autopage_tags.html +++ b/examples/03-tags/_layouts/autopage_tags.html @@ -9,7 +9,7 @@
-

AutoPage for Tag {% if page.autopages %}{{page.autopages.display_name}}{% endif %}

+

AutoPage for Tag {% if page.autopages %}{{page.autopages.display_name}}{% endif %} Page {{page.pagination_info.curr_page}} of {{page.pagination_info.total_pages}}

This page is automagically created and paginated for each tag available in the posts on this site diff --git a/lib/jekyll-paginate-v2/generator/paginationModel.rb b/lib/jekyll-paginate-v2/generator/paginationModel.rb index b1f0ead..0af1766 100644 --- a/lib/jekyll-paginate-v2/generator/paginationModel.rb +++ b/lib/jekyll-paginate-v2/generator/paginationModel.rb @@ -245,7 +245,7 @@ def paginate(template, config, site_title, all_posts, all_tags, all_categories, # 1. Create the in-memory page # External Proc call to create the actual page for us (this is passed in when the pagination is run) - newpage = PaginationPage.new( template, true ) + newpage = PaginationPage.new( template, cur_page_nr, total_pages ) # 2. Create the url for the in-memory page (calc permalink etc), construct the title, set all page.data values needed paginated_page_url = config['permalink'] diff --git a/lib/jekyll-paginate-v2/generator/paginationPage.rb b/lib/jekyll-paginate-v2/generator/paginationPage.rb index e6ef7ac..8be1fcf 100644 --- a/lib/jekyll-paginate-v2/generator/paginationPage.rb +++ b/lib/jekyll-paginate-v2/generator/paginationPage.rb @@ -9,7 +9,7 @@ module PaginateV2::Generator # This page exists purely in memory and is not read from disk # class PaginationPage < Page - def initialize(page_to_copy, ignored) + def initialize(page_to_copy, cur_page_nr, total_pages) @site = page_to_copy.site @base = '' @url = '' @@ -30,6 +30,9 @@ def initialize(page_to_copy, ignored) end end + # Store the current page and total page numbers in the pagination_info construct + self.data['pagination_info'] = {"curr_page" => cur_page_nr, 'total_pages' => total_pages } + # Perform some validation that is also performed in Jekyll::Page validate_data! page_to_copy.path validate_permalink! page_to_copy.path diff --git a/lib/jekyll-paginate-v2/version.rb b/lib/jekyll-paginate-v2/version.rb index d02471e..5d0c011 100644 --- a/lib/jekyll-paginate-v2/version.rb +++ b/lib/jekyll-paginate-v2/version.rb @@ -1,8 +1,10 @@ module Jekyll module PaginateV2 - VERSION = "1.7.2" + VERSION = "1.7.3" # When modifying remember to issue a new tag command in git before committing, then push the new tag - # git tag -a v1.7.2 -m "Gem v1.7.2" - # git push origin --tags + # git tag -a v1.7.3 -m "Gem v1.7.3" + # git push origin --tags + # Yanking a published Gem + # gem yank jekyll-paginate-v2 -v VERSION end # module PaginateV2 end # module Jekyll \ No newline at end of file