Skip to content

Commit

Permalink
Adding pagination meta information structure. Fixes #11. Bumping vers…
Browse files Browse the repository at this point in the history
…ion to 1.7.3
  • Loading branch information
sverrirs committed Feb 3, 2017
1 parent e3f93a8 commit 97bf6f5
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 9 deletions.
3 changes: 3 additions & 0 deletions README-AUTOPAGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
16 changes: 16 additions & 0 deletions README-GENERATOR.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 `<title>Index (page 2)</title>` |
| :max | total number of pages | Page with paginate config `title: ":num of :max"` the third page of 10 will become `<title>3 of 10</title>"` |
## 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
<h2>Page {{page.pagination_info.curr_page}} of {{page.pagination_info.total_pages}}</h2>
```

## Common issues

### I keep getting a dependency error when running jekyll serve after installing this gem
Expand Down
2 changes: 1 addition & 1 deletion examples/03-tags/_layouts/autopage_cat.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<div class="home">

<h1 class="page-heading">AutoPage Category <b>{% if page.autopages %}{{page.autopage.display_name}}{% endif %}</b></h1>
<h1 class="page-heading">AutoPage Category <b>{% if page.autopages %}{{page.autopage.display_name}}{% endif %}</b> Page {{page.pagination_info.curr_page}} of {{page.pagination_info.total_pages}}</h1>

Omg! all the categories in one paginated place

Expand Down
2 changes: 1 addition & 1 deletion examples/03-tags/_layouts/autopage_collection.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<div class="home">

<h1 class="page-heading">AutoPage Collection <b>{% if page.autopages %}{{page.autopages.display_name}}{% endif %}</b></h1>
<h1 class="page-heading">AutoPage Collection <b>{% if page.autopages %}{{page.autopages.display_name}}{% endif %}</b> Page {{page.pagination_info.curr_page}} of {{page.pagination_info.total_pages}}</h1>

AUTO CREATED FOR ALL COLLECTIONS IN THE SITE

Expand Down
2 changes: 1 addition & 1 deletion examples/03-tags/_layouts/autopage_collections_tags.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<div class="home">

<h1 class="page-heading">AutoPage Collection ALL : Tag <b>{% if page.autopages %}{{page.autopages.display_name}}{% endif %}</b></h1>
<h1 class="page-heading">AutoPage Collection ALL : Tag <b>{% if page.autopages %}{{page.autopages.display_name}}{% endif %}</b> Page {{page.pagination_info.curr_page}} of {{page.pagination_info.total_pages}}</h1>

This page is automagically created and paginated for each tag available in the posts on this site

Expand Down
2 changes: 1 addition & 1 deletion examples/03-tags/_layouts/autopage_tags.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<div class="home">

<h1 class="page-heading">AutoPage for Tag <b>{% if page.autopages %}{{page.autopages.display_name}}{% endif %}</b></h1>
<h1 class="page-heading">AutoPage for Tag <b>{% if page.autopages %}{{page.autopages.display_name}}{% endif %}</b> Page {{page.pagination_info.curr_page}} of {{page.pagination_info.total_pages}}</h1>

This page is automagically created and paginated for each tag available in the posts on this site

Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll-paginate-v2/generator/paginationModel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
5 changes: 4 additions & 1 deletion lib/jekyll-paginate-v2/generator/paginationPage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions lib/jekyll-paginate-v2/version.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 97bf6f5

Please sign in to comment.