j1_paginator 2019.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a8241f4f71ab4d1b22746525e356ed692fab0e937524f4afcedaa95ad03f90e6
4
+ data.tar.gz: 5be41fcb283807e00bd94abd24fc02247bcb04c76fa5006187766c25ddc6def9
5
+ SHA512:
6
+ metadata.gz: 3b6bd0fdb16817e6ef9d06cfa993cc8ed4458208ab7d4f53fda707bccf31fe10a96c12af448390530041e31299dd40a72b3d29c7fdae3d91d0f35cfe477068e3
7
+ data.tar.gz: f2afb782549b09f4cd30bf453443f1f26c8b337337d0b59b747cdb4337d4c8ee15dd96bc5c67529baf07650f53b4626237c4f3866d92acecbf3c6c879da641db
@@ -0,0 +1,86 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ > “Be kind,
4
+ >
5
+ > for everyone you meet is fighting a harder battle.”
6
+ >
7
+ > --Plato
8
+
9
+
10
+ ## TL;DR
11
+ Try to be the best version of yourself and to be excellent to others.
12
+
13
+ :purple_heart:
14
+
15
+ ## Our Pledge
16
+
17
+ In the interest of fostering an open and welcoming environment, we as
18
+ contributors and maintainers pledge to making participation in our project and
19
+ our community a harassment-free experience for everyone, regardless of age, body
20
+ size, disability, ethnicity, gender identity and expression, level of experience,
21
+ nationality, personal appearance, race, religion, or sexual identity and
22
+ orientation.
23
+
24
+ ## Our Standards
25
+
26
+ Examples of behavior that contributes to creating a positive environment
27
+ include:
28
+
29
+ * Using welcoming and inclusive language
30
+ * Being respectful of differing viewpoints and experiences
31
+ * Gracefully accepting constructive criticism
32
+ * Focusing on what is best for the community
33
+ * Showing empathy towards other community members
34
+
35
+ Examples of unacceptable behavior by participants include:
36
+
37
+ * The use of sexualized language or imagery and unwelcome sexual attention or
38
+ advances
39
+ * Trolling, insulting/derogatory comments, and personal or political attacks
40
+ * Public or private harassment
41
+ * Publishing others' private information, such as a physical or electronic
42
+ address, without explicit permission
43
+ * Other conduct which could reasonably be considered inappropriate in a
44
+ professional setting
45
+
46
+ ## Our Responsibilities
47
+
48
+ Project maintainers are responsible for clarifying the standards of acceptable
49
+ behavior and are expected to take appropriate and fair corrective action in
50
+ response to any instances of unacceptable behavior.
51
+
52
+ Project maintainers have the right and responsibility to remove, edit, or
53
+ reject comments, commits, code, wiki edits, issues, and other contributions
54
+ that are not aligned to this Code of Conduct, or to ban temporarily or
55
+ permanently any contributor for other behaviors that they deem inappropriate,
56
+ threatening, offensive, or harmful.
57
+
58
+ ## Scope
59
+
60
+ This Code of Conduct applies both within project spaces and in public spaces
61
+ when an individual is representing the project or its community. Examples of
62
+ representing a project or community include using an official project e-mail
63
+ address, posting via an official social media account, or acting as an appointed
64
+ representative at an online or offline event. Representation of a project may be
65
+ further defined and clarified by project maintainers.
66
+
67
+ ## Enforcement
68
+
69
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
70
+ reported by contacting the project team at [jekyll@sverrirs.com](mailto:jekyll@sverrirs.com). All
71
+ complaints will be reviewed and investigated and will result in a response that
72
+ is deemed necessary and appropriate to the circumstances. The project team is
73
+ obligated to maintain confidentiality with regard to the reporter of an incident.
74
+ Further details of specific enforcement policies may be posted separately.
75
+
76
+ Project maintainers who do not follow or enforce the Code of Conduct in good
77
+ faith may face temporary or permanent repercussions as determined by other
78
+ members of the project's leadership.
79
+
80
+ ## Attribution
81
+
82
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
83
+ available at [http://contributor-covenant.org/version/1/4][version]
84
+
85
+ [homepage]: http://contributor-covenant.org
86
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in j1_paginator.gemspec
4
+ gemspec
5
+
6
+ if ENV["JEKYLL_VERSION"]
7
+ gem "jekyll", "~> #{ENV["JEKYLL_VERSION"]}"
8
+ end
9
+
10
+ # adding dev-dependencies to Gemfile (instead of gemspec) allows calling
11
+ # `bundle exec [executable] [options]` more easily.
12
+ group :test do
13
+ gem "rubocop", "~> 0.51.0"
14
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Sverrir Sigmundarson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,141 @@
1
+ # Jekyll::Paginate V2::AutoPages
2
+
3
+ **AutoPages** are an optional pagination addon that can automatically generate paginated pages for all your collections, tags and categories used in the pages on your site. This is useful if you have a large site where paginating the contents of your collections, tags or category lists provides a better user experience.
4
+
5
+ <p align="center">
6
+ <img src="https://raw.githubusercontent.com/sverrirs/j1_paginator/master/res/autopages-logo.png" height="128" />
7
+ </p>
8
+
9
+
10
+ > 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! :)
11
+
12
+ * [Site configuration](#site-configuration)
13
+ * [Simple configuration](#simple-configuration)
14
+ + [Obtaining the original Tag or Category name](#obtaining-the-original-tag-or-category-name)
15
+ * [Advanced configuration](#advanced-configuration)
16
+ * [Specialised pages](#specialised-pages)
17
+ * [Considerations](#considerations)
18
+ + [Title should not contain pagination macros](#title-should-not-contain-pagination-macros)
19
+ * [Example Sites](https://github.com/sverrirs/j1_paginator/tree/master/examples)
20
+ * [Common issues](#common-issues)
21
+
22
+ :warning: Please note, this feature is still **experimental** and might not be ready for production yet.
23
+
24
+ ## Site configuration
25
+
26
+ ``` yml
27
+ ############################################################
28
+ # Site configuration for the Auto-Pages feature
29
+ # The values here represent the defaults if nothing is set
30
+ autopages:
31
+
32
+ # Site-wide kill switch, disable here and it doesn't run at all
33
+ enabled: false
34
+
35
+ # Category pages, omit entire config element to disable
36
+ categories:
37
+ # Optional, the list of layouts that should be processed for every category found in the site
38
+ layouts:
39
+ - 'autopage_category.html'
40
+ # Optional, the title that each category paginate page should get (:cat is replaced by the Category name)
41
+ title: 'Posts in category :cat'
42
+ # Optional, the permalink for the pagination page (:cat is replaced),
43
+ # the pagination permalink path is then appended to this permalink structure
44
+ permalink: '/category/:cat'
45
+
46
+ # Collection pages, omit to disable
47
+ collections:
48
+ layouts:
49
+ - 'autopage_collection.html'
50
+ title: 'Posts in collection :coll' # :coll is replaced by the collection name
51
+ permalink: '/collection/:coll'
52
+
53
+ # Tag pages, omit to disable
54
+ tags:
55
+ layouts:
56
+ - 'autopage_tags.html'
57
+ title: 'Posts tagged with :tag' # :tag is replaced by the tag name
58
+ permalink: '/tag/:tag'
59
+ ```
60
+
61
+ ## Simple configuration
62
+ The only thing needed to enable the auto pages is to add the configuration element to the site.config file and then create a layout that the pages should use.
63
+
64
+ Example of a simple autopage layout can be seen in Example 3 [examples/03-tags/_layouts/autopage_tags.html](https://github.com/sverrirs/j1_paginator/blob/master/examples/03-tags/_layouts/autopage_tags.html).
65
+
66
+ The layout does not need anything special beyond the normal pagination logic (e.g. `for post in paginator.posts` and then the next/prev arrows). You can either name the layouts by the default names (see site configuration section above) or give them a custom name and add them to the `layouts:` configuration for the relevant type of autopage.
67
+
68
+ ### Obtaining the original Tag or Category name
69
+ Internally the autopage system will trim and downcase the indexing key (tag, category or collection name). To retrieve the original name of the index key you can use the `autopages.display_name` liquid variable.
70
+
71
+ ``` html
72
+ <h1 class="page-heading">All pages tagged with <b>{% if page.autopages %}{{page.autopages.display_name}}{% endif %}</b></h1>
73
+ ```
74
+
75
+ This variable returns the untouched key value. As an example if your site uses the tag `Science-Fiction` then
76
+
77
+ ```
78
+ page.tag = "science-fiction"
79
+ page.autopages.display_name = "Science-Fiction"
80
+ ```
81
+
82
+ See [#6](https://github.com/sverrirs/j1_paginator/issues/6) for more information.
83
+
84
+
85
+ ## Advanced configuration
86
+ You can customize the look an feel of the permalink structure and the title for the auto-pages. You can also add front-matter `pagination` configuration to the layout pages you're using to specify things like sorting, filtering and all the other configuration options that are available in the normal pagination generator.
87
+
88
+ > Keep in mind that when the autopages are paginated the pagination permalink structure and pagination title suffix is appended to them.
89
+
90
+ ## Specialised pages
91
+
92
+ Special autopages can be used that leverage the powerful filtering and sorting features of the pagination logic. For example you might want to create special pages autopages that paginate all tags in a certain collection or certain tags within a category.
93
+
94
+ To achieve this you specify the `pagination` front-matter configuration in the autopage layout file.
95
+
96
+ An example of this can be found in [examples/03-tags/_layouts/autopage_collections_tags.html](https://github.com/sverrirs/j1_paginator/blob/master/examples/03-tags/_layouts/autopage_collections_tags.html). This page creates paginated pages for all tags that are found in the special _all_ collections.
97
+
98
+ ## Considerations
99
+
100
+ ### Title should not contain pagination macros
101
+ There is no need to include the pagination title macros `:num`, `:max` or `:title` in the title configuration. The autopages will use the title configuration from the pagination configuration itself.
102
+
103
+ ### Categories and tags with spaces
104
+ If you have category or tag names with spaces, make sure you use either
105
+ 1. the singular forms (`tag`, `category`), or
106
+ 2. the plural forms (`tags`, `categories`) using the YAML array syntax.
107
+
108
+ See [Filtering categories](https://github.com/sverrirs/j1_paginator/blob/master/README-GENERATOR.md#filtering-categories) for more information.
109
+
110
+ ### Special characters
111
+
112
+ As of v1.9.4, special characters are supported in category, tag, and collection names by default:
113
+
114
+ ``` yml
115
+ category: sports car, b+w
116
+ ```
117
+
118
+ If you need to support the previous behavior where special characters are replaced with hyphens in URLs, use the new `slugify` option:
119
+
120
+ ``` yml
121
+ autopages:
122
+ categories:
123
+ enabled: true
124
+ slugify:
125
+ mode: nil
126
+ cased: true
127
+ ```
128
+
129
+ The following modes are available:
130
+
131
+ | Value| Description |
132
+ | --- | --- |
133
+ | `none` | No conversion (default) |
134
+ | `raw` | Replace sequences of spaces with a hyphen |
135
+ | `nil` | Replace non-alphabetic characters with a hyphen |
136
+ | `pretty` | Keep some non-alphabetic characters (._~!$&'()+,;=@) |
137
+
138
+ If `cased` is set to `true`, all uppercase letters are replaced with their lowercase counterparts.
139
+
140
+ ## Common issues
141
+ _None reported so far_
@@ -0,0 +1,708 @@
1
+ # Jekyll::Paginate V2::Generator
2
+
3
+ The **Generator** forms the core of the pagination logic. It is responsible for reading the posts and collections in your site and split them correctly across multiple pages according to the supplied configuration. It also performs the necessary functions to link to the previous and next pages in the page-sets that it generates.
4
+ <p align="center">
5
+ <img src="https://raw.githubusercontent.com/sverrirs/j1_paginator/master/res/generator-logo.png" height="128" />
6
+ </p>
7
+
8
+ > The code was based on the original design of [jekyll-paginate](https://github.com/jekyll/jekyll-paginate) and features were sourced from discussions such as [#27](https://github.com/jekyll/jekyll-paginate/issues/27) (thanks [Günter Kits](https://github.com/gynter)).
9
+
10
+ * [Site configuration](#site-configuration)
11
+ * [Page configuration](#page-configuration)
12
+ * [Backwards compatibility](#backwards-compatibility-with-jekyll-paginate)
13
+ * [Example Sites](https://github.com/sverrirs/j1_paginator/tree/master/examples)
14
+ * [Paginating collections](#paginating-collections)
15
+ + [Single collection](#paginating-a-single-collection)
16
+ + [Multiple collection](#paginating-multiple-collections)
17
+ + [The special 'all' collection](#the-special-all-collection)
18
+ * [How to paginate categories, tags, locales](#paginate-categories-tags-locales)
19
+ + [Filtering categories](#filtering-categories)
20
+ + [Filtering tags](#filtering-tags)
21
+ + [Filtering locales](#filtering-locales)
22
+ * [How to paginate on combination of filters](#paginate-on-combination-of-filters)
23
+ * [Overriding site configuration](#configuration-overrides)
24
+ * [Offsetting posts (how to skip newest posts)](#offsetting-posts)
25
+ * [Advanced Sorting](#advanced-sorting)
26
+ * [Creating Pagination Trails](#creating-pagination-trails)
27
+ * [How to detect auto-generated pages](#detecting-generated-pagination-pages)
28
+ * [Formatting page titles](#formatting-page-titles)
29
+ * [Reading pagination meta information](#reading-pagination-meta-information)
30
+ * [How to generate a JSON API](#generating-a-json-api)
31
+ * [Renaming pagination file names](#renaming-pagination-file-names)
32
+ * [Common issues](#common-issues)
33
+ - [Dependency Error after installing](#i-keep-getting-a-dependency-error-when-running-jekyll-serve-after-installing-this-gem)
34
+ - [Bundler error upgrading gem (Bundler::GemNotFound)](#im-getting-a-bundler-error-after-upgrading-the-gem-bundlergemnotfound)
35
+ - [Bundler error running gem (Gem::LoadError)](#im-getting-a-bundler-error-after-upgrading-the-gem-gemloaderror)
36
+ - [Pagination pages are not found](#my-pagination-pages-are-not-being-found-couldnt-find-any-pagination-page-skipping-pagination)
37
+ - [Categories cause excess folder nesting](#my-pages-are-being-nested-multiple-levels-deep)
38
+ - [Pagination pages overwriting each others pages](#my-pagination-pages-are-overwriting-each-others-pages)
39
+
40
+ ## Site configuration
41
+
42
+ The pagination gem is configured in the site's `_config.yml` file by including the `pagination` configuration element
43
+
44
+ ``` yml
45
+ ############################################################
46
+ # Site configuration for the Jekyll 3 Pagination Gem
47
+ # The values here represent the defaults if nothing is set
48
+ pagination:
49
+
50
+ # Site-wide kill switch, disabled here it doesn't run at all
51
+ enabled: true
52
+
53
+ # Set to 'true' to enable pagination debugging. This can be enabled in the site config or only for individual pagination pages
54
+ debug: false
55
+
56
+ # The default document collection to paginate if nothing is specified ('posts' is default)
57
+ collection: 'posts'
58
+
59
+ # How many objects per paginated page, used to be `paginate` (default: 0, means all)
60
+ per_page: 10
61
+
62
+ # The permalink structure for the paginated pages (this can be any level deep)
63
+ permalink: '/page/:num/' # Pages are index.html inside this folder (default)
64
+ #permalink: '/page/:num.html' # Pages are simple html files
65
+ #permalink: '/page/:num' # Pages are html files, linked jekyll extensionless permalink style.
66
+
67
+ # Optional the title format for the paginated pages (supports :title for original page title, :num for pagination page number, :max for total number of pages)
68
+ title: ':title - page :num'
69
+
70
+ # Limit how many pagenated pages to create (default: 0, means all)
71
+ limit: 0
72
+
73
+ # Optional, defines the field that the posts should be sorted on (omit to default to 'date')
74
+ sort_field: 'date'
75
+
76
+ # Optional, sorts the posts in reverse order (omit to default decending or sort_reverse: true)
77
+ sort_reverse: true
78
+
79
+ # Optional, the default category to use, omit or just leave this as 'posts' to get a backwards-compatible behavior (all posts)
80
+ category: 'posts'
81
+
82
+ # Optional, the default tag to use, omit to disable
83
+ tag: ''
84
+
85
+ # Optional, the default locale to use, omit to disable (depends on a field 'locale' to be specified in the posts,
86
+ # in reality this can be any value, suggested are the Microsoft locale-codes (e.g. en_US, en_GB) or simply the ISO-639 language code )
87
+ locale: ''
88
+
89
+ # Optional,omit or set both before and after to zero to disable.
90
+ # Controls how the pagination trail for the paginated pages look like.
91
+ trail:
92
+ before: 2
93
+ after: 2
94
+
95
+ # Optional, the default file extension for generated pages (e.g html, json, xml).
96
+ # Internally this is set to html by default
97
+ extension: html
98
+
99
+ # Optional, the default name of the index file for generated pages (e.g. 'index.html')
100
+ # Without file extension
101
+ indexpage: 'index'
102
+
103
+ ############################################################
104
+ ```
105
+
106
+ Also ensure that you remove the old 'jekyll-paginate' gem from your `gems` list and add this new gem instead
107
+
108
+ ``` yml
109
+ gems: [j1_paginator]
110
+ ```
111
+
112
+ ## Page configuration
113
+
114
+ To enable pagination on a page then simply include the minimal pagination configuration in the page front-matter:
115
+
116
+ ``` yml
117
+ ---
118
+ layout: page
119
+ pagination:
120
+ enabled: true
121
+ ---
122
+ ```
123
+
124
+ Then you can use the normal `paginator.posts` logic to iterate through the posts.
125
+
126
+ ``` html
127
+ {% for post in paginator.posts %}
128
+ <h1>{{ post.title }}</h1>
129
+ {% endfor %}
130
+ ```
131
+
132
+ And to display pagination links, simply
133
+
134
+ ``` html
135
+ {% if paginator.total_pages > 1 %}
136
+ <ul>
137
+ {% if paginator.previous_page %}
138
+ <li>
139
+ <a href="{{ paginator.previous_page_path | prepend: site.baseurl }}">Newer</a>
140
+ </li>
141
+ {% endif %}
142
+ {% if paginator.next_page %}
143
+ <li>
144
+ <a href="{{ paginator.next_page_path | prepend: site.baseurl }}">Older</a>
145
+ </li>
146
+ {% endif %}
147
+ </ul>
148
+ {% endif %}
149
+ ```
150
+
151
+ > All posts that have the `hidden: true` in their front matter are ignored by the pagination logic.
152
+
153
+ Following fields area available on the `paginator` object
154
+
155
+ | Field | Description |
156
+ | --- | --- |
157
+ | per_page | Maximum number of posts or documents on each pagination page. |
158
+ | posts | The list of post objects that belong to this pagination page. |
159
+ | total_posts | Total number of posts included in pagination. |
160
+ | total_pages | Total number of pagination pages created. |
161
+ | page | Number of the current pagination page. |
162
+ | page_path | The relative Url path of the current pagination page. |
163
+ | previous_page | Number of the previous page in the pagination. Nil if no previous page is available. |
164
+ | previous_page_path | The relative Url of the previous page. Nil if no previous page is available. |
165
+ | next_page | Number of the next page in the pagination. Nil if there is no next page available. |
166
+ | next_page_path | The relative Url of the next page in the pagination. Nil if there is no next page available. |
167
+ | first_page | Number of the first page in the pagination (usually this is `1`). |
168
+ | first_page_path | The relative Url of the first page in the pagination. |
169
+ | last_page | Number of the last page in the pagination (this is equal to `total_pages`). |
170
+ | last_page_path | The relative Url of the last page in the pagination. |
171
+ | page_trail | The [pagination trail](#creating-pagination-trails) structure |
172
+
173
+
174
+ The code is fully backwards compatible and you will have access to all the normal paginator variables defined in the [official jekyll documentation](https://jekyllrb.com/docs/pagination/#liquid-attributes-available).
175
+
176
+ Neat! :ok_hand:
177
+
178
+ Don't delay, go see the [Examples](https://github.com/sverrirs/j1_paginator/tree/master/examples), they're way more useful than read-me docs at this point :)
179
+
180
+ ## Backwards compatibility with jekyll-paginate
181
+ This gem is fully backwards compatible with the old [jekyll-paginate](https://github.com/jekyll/jekyll-paginate) gem and can be used as a zero-configuration replacement for it. If the old site config is detected then the gem will fall back to the old logic of pagination.
182
+
183
+ > You cannot run both the new pagination logic and the old one at the same time
184
+
185
+ The following `_config.yml` settings are honored when running this gem in compatability mode
186
+
187
+ ``` yml
188
+ paginate: 8
189
+ paginate_path: "/legacy/page:num/"
190
+ ```
191
+
192
+ See more about the old style of pagination at the [jekyll-paginate](https://github.com/jekyll/jekyll-paginate) page.
193
+
194
+ > :bangbang: **Warning** Backwards compatibility with the old jekyll-paginate gem is currently scheduled to be removed after **1st January 2018**. Users will start receiving warning log messages when running jekyll two months before this date.
195
+
196
+ ## Paginating collections
197
+ By default the pagination system only paginates `posts`. If you only have `posts` and `pages` in your site you don't need to worry about a thing, everything will work as intended without you configuring anything.
198
+
199
+ However if you use document collections, or would like to, then this pagination gem offers extensive support for paginating documents in one or more collections at the same time.
200
+
201
+ > Collections are groups of documents that belong together but should not be grouped by date.
202
+ > See more about ['collections'](http://ben.balter.com/2015/02/20/jekyll-collections/) on Ben Balters blog.
203
+
204
+ ### Paginating a single collection
205
+
206
+ Lets expand on Ben's collection discussion (linked above). Let's say that you have hundreds of cupcake pages in your cupcake collection. To create a pagination page for only documents from the cupcake collection you would do this
207
+
208
+ ``` yml
209
+ ---
210
+ layout: page
211
+ title: All Cupcakes
212
+ pagination:
213
+ enabled: true
214
+ collection: cupcakes
215
+ ---
216
+ ```
217
+
218
+ ### Paginating multiple collections
219
+
220
+ Lets say that you want to create a single pagination page for only small cakes on your page (you have both cupcakes and cookies to sell). You could do that like this
221
+
222
+ ``` yml
223
+ ---
224
+ layout: page
225
+ title: Lil'bits
226
+ pagination:
227
+ enabled: true
228
+ collection: cupcakes, cookies
229
+ ---
230
+ ```
231
+
232
+ ### The special 'all' collection
233
+
234
+ Now your site has grown and you have multiple cake collections on it and you want to have a single page that paginates all of your collections at the same time.
235
+ You can use the special `all` collection name for this.
236
+
237
+ ``` yml
238
+ ---
239
+ layout: page
240
+ title: All the Cakes!
241
+ pagination:
242
+ enabled: true
243
+ collection: all
244
+ ---
245
+ ```
246
+
247
+ > Note: Due to the `all` keyword being reserved for this feature, you cannot have a collection called `all` in your site configuration. Sorry.
248
+
249
+
250
+ ## Paginate categories, tags, locales
251
+
252
+ Enabling pagination for specific categories, tags or locales is as simple as adding values to the pagination page front-matter and corresponding values in the posts.
253
+
254
+ ### Filtering categories
255
+
256
+ Filter single category 'software'
257
+
258
+ ``` yml
259
+ ---
260
+ layout: post
261
+ pagination:
262
+ enabled: true
263
+ category: software
264
+ ---
265
+ ```
266
+
267
+ Filter multiple categories (lists only posts belonging to all categories)
268
+
269
+ ``` yml
270
+ pagination:
271
+ enabled: true
272
+ category: software, ruby
273
+ ```
274
+
275
+ You may use also use `categories` instead:
276
+
277
+ ``` yml
278
+ pagination:
279
+ enabled: true
280
+ categories:
281
+ - software
282
+ - ruby
283
+ ```
284
+
285
+ **Note:** Do *not* use `categories` as follows:
286
+
287
+ ``` yml
288
+ categories: programming language, ruby
289
+ ```
290
+
291
+ i.e. with category names that have spaces in them. Jekyll will split the above using spaces as the delimiter, resulting in `programming`, `language,`, and `ruby` as categories. Instead, use
292
+
293
+ ``` yml
294
+ category: programming language, ruby
295
+ ```
296
+
297
+ or
298
+
299
+ ``` yml
300
+ categories:
301
+ - programming language
302
+ - ruby
303
+ ```
304
+
305
+ > To define categories you can either specify them in the front-matter or through the [directory structure](http://jekyllrb.com/docs/variables/#page-variables) of your jekyll site (Categories are derived from the directory structure above the \_posts directory). You can actually use both approaches to assign your pages to multiple categories.
306
+
307
+ ### Filtering tags
308
+
309
+ Filter on a single tag
310
+
311
+ ``` yml
312
+ pagination:
313
+ enabled: true
314
+ tag: cool
315
+ ```
316
+
317
+ Filter on multiple tags
318
+
319
+ ``` yml
320
+ pagination:
321
+ enabled: true
322
+ tag: cool, life
323
+ ```
324
+
325
+ As with categories, you may also use the following syntax:
326
+
327
+ ``` yml
328
+ pagination:
329
+ enabled: true
330
+ tags:
331
+ - cool
332
+ - life
333
+ ```
334
+
335
+ > When specifying tags in your posts make sure that the values are not enclosed in single quotes (double quotes are fine). If they are you will get a cryptic error when generating your site that looks like _"Error: could not read file <FILE>: did not find expected key while parsing a block mapping at line 2 column 1"_
336
+
337
+ ### Filtering locales
338
+
339
+ In the case your site offers multiple languages you can include a `locale` item in your post front matter. The paginator can then use this value to filter on
340
+
341
+ The category page front-matter would look like this
342
+
343
+ ``` yml
344
+ pagination:
345
+ enabled: true
346
+ locale: en_US
347
+ ```
348
+
349
+ Then for the relevant posts, include the `locale` variable in their front-matter
350
+
351
+ ``` yml
352
+ locale: en_US
353
+ ```
354
+
355
+ ## Paginate on combination of filters
356
+
357
+ Including only posts from categories 'ruby' and 'software' written in English
358
+
359
+ ``` yml
360
+ pagination:
361
+ enabled: true
362
+ category: software, ruby
363
+ locale: en_US, en_GB, en_WW
364
+ ```
365
+
366
+ Only showing posts tagged with 'cool' and in category 'cars'
367
+
368
+ ``` yml
369
+ pagination:
370
+ enabled: true
371
+ category: cars
372
+ tag: cool
373
+ ```
374
+
375
+ ... and so on and so on
376
+
377
+ ## Configuration overrides
378
+
379
+ All of the configuration elements from the `_config.yml` file can be overwritten in the pagination pages. E.g. if you want one category page to have different permalink structure simply override the item like so
380
+
381
+ ``` yml
382
+ pagination:
383
+ enabled: true
384
+ category: cars
385
+ permalink: '/cars/:num/'
386
+ ```
387
+
388
+ Overriding sorting to sort by the post title in ascending order for another paginated page could be done like so
389
+
390
+ ``` yml
391
+ pagination:
392
+ enabled: true
393
+ category: ruby
394
+ sort_field: 'title'
395
+ sort_reverse: false
396
+ ```
397
+
398
+ ## Offsetting posts
399
+ The paging logic can be instructed to exclude the first _N_ number of newest posts from the pagination.
400
+ This can be useful in situations where your site treats the first N posts differently from the rest (e.g. a featured post that is always present).
401
+
402
+ The number of pages to skip is configured using the `offset` setting like so
403
+
404
+ ``` yml
405
+ pagination:
406
+ enabled: true
407
+ offset: 3
408
+ ```
409
+
410
+ This example skips the 3 newest posts from the pagination logic.
411
+
412
+ ## Advanced Sorting
413
+ Sorting can be done by any field that is available in the post front-matter. You can even sort by nested fields.
414
+
415
+ > When sorting by nested fields separate the fields with a colon `:` character.
416
+
417
+ As an example, assuming all your posts have the following front-matter
418
+
419
+ ``` yml
420
+ ---
421
+ layout: post
422
+ author:
423
+ name:
424
+ first: "John"
425
+ last: "Smith"
426
+ born: 1960
427
+ ---
428
+ ```
429
+
430
+ You can define pagination sorting on the nested `first` field like so
431
+
432
+ ``` yml
433
+ ---
434
+ layout: page
435
+ title: "Authors by first name"
436
+ pagination:
437
+ enabled: true
438
+ sort_field: 'author:name:first'
439
+ ---
440
+ ```
441
+
442
+ To sort by the `born` year in decending order (youngest first)
443
+
444
+ ``` yml
445
+ ---
446
+ layout: page
447
+ title: "Authors by birth year"
448
+ pagination:
449
+ enabled: true
450
+ sort_field: 'author:born'
451
+ sort_reverse: true
452
+ ---
453
+ ```
454
+
455
+ ## Creating Pagination Trails
456
+
457
+ <p align="center">
458
+ <img src="https://raw.githubusercontent.com/sverrirs/j1_paginator/master/res/pagination-trails.png" />
459
+ </p>
460
+
461
+ Creating a trail structure for your pagination as shown above can be achieved by enabling the `trail` configuration and including a little extra code in your liquid templates.
462
+
463
+ ``` yml
464
+ pagination:
465
+ trail:
466
+ before: 2 # The number of links before the current page
467
+ after: 2 # The number of links after the current page
468
+ ```
469
+
470
+ Your layout file would then have to include code similar to the following to generate the correct HTML structure
471
+
472
+ ``` HTML
473
+ {% if paginator.page_trail %}
474
+ {% for trail in paginator.page_trail %}
475
+ <li {% if page.url == trail.path %}class="selected"{% endif %}>
476
+ <a href="{{ trail.path | prepend: site.baseurl }}" title="{{trail.title}}">{{ trail.num }}</a>
477
+ </li>
478
+ {% endfor %}
479
+ {% endif %}
480
+ ```
481
+ _See [example 3](https://github.com/sverrirs/j1_paginator/tree/master/examples/03-tags) for a demo of a pagination trail_
482
+
483
+ The `trail` object exposes three properties:
484
+ * `num`: The number of the page
485
+ * `path`: The path to the page
486
+ * `title`: The title of the page
487
+
488
+ The algorithm will always attempt to keep the same trail length for all pages (`trail length = before + after + 1`).
489
+ As an example if we have only 7 pagination pages in total and the user is currently on page 6 then the trail would look like this
490
+
491
+ <p align="center">
492
+ <img src="https://raw.githubusercontent.com/sverrirs/j1_paginator/master/res/pagination-trails-p6.png" />
493
+ </p>
494
+
495
+ Different number of before and after trail links can be specified. Below is an example of how the yml config below would look like when on the same page 4
496
+
497
+ ``` yml
498
+ pagination:
499
+ trail:
500
+ before: 1
501
+ after: 3
502
+ ```
503
+
504
+ <p align="center">
505
+ <img src="https://raw.githubusercontent.com/sverrirs/j1_paginator/master/res/pagination-trails-p4-b1a3.png" />
506
+ </p>
507
+
508
+ ## Detecting generated pagination pages
509
+
510
+ To identify the auto-generated pages that are created by the pagination logic when iterating through collections such as `site.pages` the `page.autogen` variable can be used like so
511
+
512
+ ```
513
+ {% for my_page in site.pages %}
514
+ {% if my_page.title and my_page.autogen == nil %}
515
+ <h1>{{ my_page.title | escape }}</h1>
516
+ {% endif %}
517
+ {% endfor %}
518
+ ```
519
+ _In this example only pages that have a title and are not auto-generated are included._
520
+
521
+ This variable is created and assigned the value `page.autogen = "j1_paginator"` by the pagination logic. This way you can detect which pages are auto-generated and by what gem.
522
+
523
+ ## Formatting page titles
524
+
525
+ The `title` field in both the site.config and the front-matter configuration supports the following macros.
526
+
527
+ | Text | Replaced with | Example |
528
+ | --- | --- | --- |
529
+ | :title | original page title | Page with `title: "Index"` and paginate config `title: ":title - split"` becomes `<title>Index - split</title>` |
530
+ | :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>` |
531
+ | :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>"` |
532
+
533
+ ## Reading pagination meta information
534
+ 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.
535
+
536
+ The following fields are available
537
+
538
+ | Field | Description |
539
+ | --- | --- |
540
+ | curr_page | The number of the current pagination page |
541
+ | total_pages | The total number of pages in this pagination |
542
+
543
+ Below is an example on how to print out a "Page x of n" in the pagination layout
544
+
545
+ ``` html
546
+ <h2>Page {{page.pagination_info.curr_page}} of {{page.pagination_info.total_pages}}</h2>
547
+ ```
548
+
549
+ ## Generating a JSON API
550
+
551
+ Delivering content via an API is useful, for a lot of the same reasons that pagination is useful. We want to delivery content, in such a way, that is:
552
+
553
+ 1. Easy for the user to consume.
554
+ 2. Easy for the browser to load.
555
+
556
+ Paginating content meets both of these requirements, but developers are limited to presenting content statically rather than dynamically. Some example of dynamic content delivery are:
557
+ - Pop up modals
558
+ - Infinite scrolling
559
+ - Multi-tiered pagination (e.g. Netflix UI horizontal scrolling for multiple movie categories)
560
+
561
+ ### So how do I generate a JSON API for Jekyll?
562
+
563
+ First, create a new jekyll page and set its layout to `null` to avoid any extra html to show up.
564
+
565
+ Next, use the `extension` and `indexpage` option to customize the output of the page and its paginated content as JSON files.
566
+ > Note that the `indexpage` field also supports the same macros as the permalink field
567
+
568
+ Here's an example page:
569
+ ```
570
+ ---
571
+ layout: null
572
+ permalink: /api
573
+ pagination:
574
+ permalink: ''
575
+ enabled: true
576
+ extension: .json
577
+ indexpage: 'feed-:num'
578
+ ---
579
+
580
+ {
581
+ "pages": [{% for post in paginator.posts %}
582
+ {% if forloop.first != true %},{% endif %}
583
+ {
584
+ "title": "{{ post.title }}",
585
+ "link": "{{ post.url }}"
586
+ }{% endfor %}
587
+ ]
588
+ }
589
+ ```
590
+ Next, run `jekyll build`. This will generate a set of paginated JSON files under the folder `/api`. These JSON files can be loaded via Javascript/AJAX to dynamically load content into your site.
591
+
592
+ Below's an example set of routes that the configuration would generate:
593
+ - http://localhost:4000/api/feed-1.json
594
+ - http://localhost:4000/api/feed-2.json
595
+ - http://localhost:4000/api/feed-3.json
596
+
597
+ And here is an example of one of the feed.json files that are created given the markup above
598
+ ```
599
+ {
600
+ "pages": [
601
+ {
602
+ "title": "Narcisse Snake Pits",
603
+ "link": "/2016/11/narcisse-snake-pits.html"
604
+ },{
605
+ "title": "Luft-Fahrzeug-Gesellschaft",
606
+ "link": "/2016/11/luft-fahrzeug-gesellschaft.html"
607
+ },{
608
+ "title": "Rotary engine",
609
+ "link": "/2016/11/rotary-engine.html"
610
+ }
611
+ ],
612
+ "next": "/api/feed-11.json",
613
+ "prev": "/api/feed-9.json",
614
+ "first": "/api/feed-1.json"
615
+ }
616
+ ```
617
+
618
+ For further information see [Example 4](https://github.com/sverrirs/j1_paginator/tree/master/examples/04-jsonapi), that project can serve as a starting point for your experiments with this feature.
619
+
620
+ ### How did you generate those 'next', 'prev' and 'first' links?
621
+
622
+ All the normal paginator variables can be used in these JSON feed files. You can use them to achive quite powerful features such as pre-loading and detecting when there are no more feeds to load.
623
+
624
+ ```
625
+ {% if paginator.next_page %}
626
+ ,"next": "{{ paginator.next_page_path }}"
627
+ {% endif %}
628
+ {% if paginator.last_page %}
629
+ ,"prev": "{{ paginator.last_page_path }}"
630
+ {% endif %}
631
+ {% if paginator.first_page %}
632
+ ,"first": "{{ paginator.first_page_path }}"
633
+ {% endif %}
634
+ ```
635
+
636
+ ## Renaming pagination file names
637
+ By default the pagination system creates all paginated pages as `index.html`. The system provides an option to override this name and file extension with the
638
+
639
+ ```yml
640
+ indexpage: index
641
+ extension: html
642
+ ```
643
+
644
+ If you wanted to generate all pagination files as `default.htm` then the settings should be configured as follows
645
+
646
+ ```yml
647
+ indexpage: default
648
+ extension: htm
649
+ ```
650
+
651
+ ## Common issues
652
+
653
+ ### I keep getting a dependency error when running jekyll serve after installing this gem
654
+
655
+ > Dependency Error: Yikes! It looks like you don't have j1_paginator or one of its dependencies installed...
656
+
657
+ Check your `Gemfile` in the site root. Ensure that the j1_paginator gem is present in the jekyll_plugins group like the example below. If this group is missing add to the file.
658
+
659
+ ``` ruby
660
+ group :jekyll_plugins do
661
+ gem "j1_paginator"
662
+ end
663
+ ```
664
+
665
+ ### I'm getting a bundler error after upgrading the gem (Bundler::GemNotFound)
666
+
667
+ > bundler/spec_set.rb:95:in `block in materialize': Could not find j1_paginator-1.0.0 in any of the sources (Bundler::GemNotFound)
668
+
669
+ Delete your `Gemfile.lock` file and try again.
670
+
671
+
672
+ ### I'm getting a bundler error after upgrading the gem (Gem::LoadError)
673
+
674
+ > bundler/runtime.rb:40:in 'block in setup': You have already activated addressable 2.5.0, but your Gemfile requires addressable 2.4.0. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)
675
+
676
+ Delete your `Gemfile.lock` file and try again.
677
+
678
+ ### My pagination pages are not being found (Couldn't find any pagination page. Skipping pagination)
679
+
680
+ > Pagination: Is enabled, but I couldn't find any pagination page. Skipping pagination...
681
+
682
+ * Ensure that you have the correct minimum front-matter in the pagination pages
683
+ ``` yml
684
+ pagination:
685
+ enabled: true
686
+ ```
687
+ * You can place pagination logic into either the pages or liquid templates (templates are stored under the `_layouts/` and `_includes/` folders).
688
+
689
+ ### My pages are being nested multiple levels deep
690
+
691
+ When using `categories` for posts it is advisable to explicitly state a `permalink` structure in your `_config.yml` file.
692
+
693
+ ```
694
+ permalink: /:year/:month/:title.html
695
+ ```
696
+
697
+ This is because the default behavior in Jekyll is to nest pages for every category that they belong to and Jekyll unfortunately does not understand multi-categories separated with `,` or `;` but instead does all separation on `[space]` only.
698
+
699
+ ### My pagination pages are overwriting each others pages
700
+ If you specify multiple pages that paginate in the site root then you must give them unique and separate pagination permalink. This link is set in the pagination page front-matter like so
701
+
702
+ ``` yml
703
+ pagination:
704
+ enabled: true
705
+ permalink: '/cars/:num/'
706
+ ```
707
+
708
+ Make absolutely sure that your pagination permalink paths do not clash with any other paths in your final site. For simplicity it is recommended that you keep all custom pagination (non root index.html) in a single or multiple separate sub folders under your site root.