jekyll-paginate-v2 1.5.2 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -12,27 +12,8 @@ Reach me at the [project issues](https://github.com/sverrirs/jekyll-paginate-v2/
12
12
 
13
13
  * [Installation](#installation)
14
14
  * [Example Sites](https://github.com/sverrirs/jekyll-paginate-v2/tree/master/examples)
15
- * [Site configuration](#site-configuration)
16
- * [Page configuration](#page-configuration)
17
- * [Backwards compatibility](#backwards-compatibility-with-jekyll-paginate)
18
- * [Paginating collections](#paginating-collections)
19
- + [Single collection](#paginating-a-single-collection)
20
- + [Multiple collection](#paginating-multiple-collections)
21
- + [The special 'all' collection](#the-special-all-collection)
22
- * [How to paginate categories, tags, locales](#paginate-categories-tags-locales)
23
- + [Filtering categories](#filtering-categories)
24
- + [Filtering tags](#filtering-tags)
25
- + [Filtering locales](#filtering-locales)
26
- * [How to paginate on combination of filters](#paginate-on-combination-of-filters)
27
- * [Overriding site configuration](#configuration-overrides)
28
- * [Advanced Sorting](#advanced-sorting)
29
- * [How to detect auto-generated pages](#detecting-generated-pagination-pages)
30
- * [Common issues](#common-issues)
31
- - [Dependency Error after installing](#i-keep-getting-a-dependency-error-when-running-jekyll-serve-after-installing-this-gem)
32
- - [Bundler error upgrading gem (Bundler::GemNotFound)](#im-getting-a-bundler-error-after-upgrading-the-gem-bundlergemnotfound)
33
- - [Pagination pages are not found](#my-pagination-pages-are-not-being-found-couldnt-find-any-pagination-page-skipping-pagination)
34
- - [Categories cause excess folder nesting](#my-pages-are-being-nested-multiple-levels-deep)
35
- - [Pagination pages overwriting each others pages](#my-pagination-pages-are-overwriting-each-others-pages)
15
+ * [Pagination Generator](#pagination-generator)
16
+ * [Auto-Pages](#auto-pages)
36
17
  * [Issues / to-be-completed](#issues--to-be-completed)
37
18
  * [How to Contribute](#contributing)
38
19
 
@@ -46,416 +27,40 @@ Reach me at the [project issues](https://github.com/sverrirs/jekyll-paginate-v2/
46
27
  gem install jekyll-paginate-v2
47
28
  ```
48
29
 
49
- Update your [_config.yml](#site-configuration) and [pages](#page-configuration).
30
+ Update your [_config.yml](README-GENERATOR.md#site-configuration) and [pages](README-GENERATOR.md#page-configuration).
50
31
 
51
- > Although fully backwards compatible, to enable the new features this gem needs slightly extended [site yml](#site-configuration) configuration and miniscule additional new front-matter for the [pages to paginate on](#page-configuration).
32
+ > Although fully backwards compatible, to enable the new features this gem needs slightly extended [site yml](README-GENERATOR.md#site-configuration) configuration and miniscule additional new front-matter for the [pages to paginate on](README-GENERATOR.md#page-configuration).
52
33
 
53
34
  Now you're ready to run `jekyll serve` and your paginated files should be generated.
54
35
 
55
36
  Please see the [Examples](https://github.com/sverrirs/jekyll-paginate-v2/tree/master/examples) for tips and tricks on how to configure the pagination logic.
56
37
 
57
- ## Site configuration
58
38
 
59
- The plugin can be configured in the site's `_config.yml` file by including the `pagination` configuration element
39
+ ## Pagination Generator
60
40
 
61
- ``` yml
62
- ############################################################
63
- # Site configuration for the Jekyll 3 Pagination Plugin
64
- # The values here represent the defaults if nothing is set
65
- pagination:
66
-
67
- # Site-wide kill switch, disabled here it doesn't run at all
68
- enabled: true
41
+ The [Pagination Generator](README-GENERATOR.md) forms the core of the pagination logic. Calculates and generates the pagination pages.
69
42
 
70
- # Set to 'true' to enable pagination debugging. This can be enabled in the site config or only for individual pagination pages
71
- debug: false
72
43
 
73
- # The default document collection to paginate if nothing is specified ('posts' is default)
74
- collection: 'posts'
44
+ ## Auto Pages
75
45
 
76
- # How many objects per paginated page, used to be `paginate` (default: 0, means all)
77
- per_page: 10
46
+ The [Auto-Pages](README-AUTOPAGES.md) is an optional feature that auto-magically generates paginated pages for all your tags, categories and collections.
78
47
 
79
- # The permalink structure for the paginated pages (this can be any level deep)
80
- permalink: '/page/:num/'
81
-
82
- # Optional the title format for the paginated pages (supports :title for original page title, :num for pagination page number)
83
- title: ':title - page :num'
84
-
85
- # Limit how many pagenated pages to create (default: 0, means all)
86
- limit: 0
87
-
88
- # Optional, defines the field that the posts should be sorted on (omit to default to 'date')
89
- sort_field: 'date'
90
-
91
- # Optional, sorts the posts in reverse order (omit to default decending or sort_reverse: true)
92
- sort_reverse: true
93
-
94
- # Optional, the default category to use, omit or just leave this as 'posts' to get a backwards-compatible behavior (all posts)
95
- category: 'posts'
96
-
97
- # Optional, the default tag to use, omit to disable
98
- tag: ''
99
-
100
- # Optional, the default locale to use, omit to disable (depends on a field 'locale' to be specified in the posts,
101
- # 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 )
102
- locale: ''
103
-
104
- ############################################################
105
- ```
106
-
107
- Also ensure that you remove the old 'jekyll-paginate' gem from your `gems` list and add this new gem instead
108
-
109
- ``` yml
110
- gems: [jekyll-paginate-v2]
111
- ```
112
-
113
- ## Page configuration
114
-
115
- To enable pagination on a page then simply include the minimal pagination configuration in the page front-matter:
116
-
117
- ``` yml
118
- ---
119
- layout: page
120
- pagination:
121
- enabled: true
122
- ---
123
- ```
124
-
125
- Then you can use the normal `paginator.posts` logic to iterate through the posts.
126
-
127
- ``` html
128
- {% for post in paginator.posts %}
129
- <h1>{{ post.title }}</h1>
130
- {% endfor %}
131
- ```
132
-
133
- And to display pagination links, simply
134
-
135
- ``` html
136
- {% if paginator.total_pages > 1 %}
137
- <ul>
138
- {% if paginator.previous_page %}
139
- <li>
140
- <a href="{{ paginator.previous_page_path | prepend: site.baseurl }}">Newer</a>
141
- </li>
142
- {% endif %}
143
- {% if paginator.next_page %}
144
- <li>
145
- <a href="{{ paginator.next_page_path | prepend: site.baseurl }}">Older</a>
146
- </li>
147
- {% endif %}
148
- </ul>
149
- {% endif %}
150
- ```
151
-
152
- > All posts that have the `hidden: true` in their front matter are ignored by the pagination logic.
153
-
154
- 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).
155
-
156
- Neat!
157
-
158
- Don't delay, go see the [Examples](https://github.com/sverrirs/jekyll-paginate-v2/tree/master/examples), they're way more useful than read-me docs at this point :)
159
-
160
- ## Backwards compatibility with jekyll-paginate
161
- 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.
162
-
163
- > You cannot run both the new pagination logic and the old one at the same time
164
-
165
- The following `_config.yml` settings are honored when running this gem in compatability mode
166
-
167
- ``` yml
168
- paginate: 8
169
- paginate_path: "/legacy/page:num/"
170
- ```
171
-
172
- See more about the old style of pagination at the [jekyll-paginate](https://github.com/jekyll/jekyll-paginate) page.
173
-
174
- > :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.
175
-
176
- ## Paginating collections
177
- 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.
178
-
179
- 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.
180
-
181
- > Collections are groups of documents that belong together but should not be grouped by date.
182
- > See more about ['collections'](http://ben.balter.com/2015/02/20/jekyll-collections/) on Ben Balters blog.
183
-
184
- ### Paginating a single collection
185
-
186
- 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
187
-
188
- ``` yml
189
- ---
190
- layout: page
191
- title: All Cupcakes
192
- pagination:
193
- enabled: true
194
- collection: cupcakes
195
- ---
196
- ```
197
-
198
- ### Paginating multiple collections
199
-
200
- 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
201
-
202
- ``` yml
203
- ---
204
- layout: page
205
- title: Lil'bits
206
- pagination:
207
- enabled: true
208
- collection: cupcakes, cookies
209
- ---
210
- ```
211
-
212
- ### The special 'all' collection
213
-
214
- 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.
215
- You can use the special `all` collection name for this.
216
-
217
- ``` yml
218
- ---
219
- layout: page
220
- title: All the Cakes!
221
- pagination:
222
- enabled: true
223
- collection: all
224
- ---
225
- ```
226
-
227
- > Note: Due to the `all` keyword being reserved for this feature, you cannot have a collection called `all` in your site configuration. Sorry.
228
-
229
-
230
- ## Paginate categories, tags, locales
231
-
232
- 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.
233
-
234
- ### Filtering categories
235
-
236
- Filter single category 'software'
237
-
238
- ``` yml
239
- ---
240
- layout: post
241
- pagination:
242
- enabled: true
243
- category: software
244
- ---
245
- ```
246
-
247
- Filter multiple categories (lists only posts belonging to all categories)
248
-
249
- ``` yml
250
- pagination:
251
- enabled: true
252
- category: software, ruby
253
- ```
254
-
255
- > 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.
256
-
257
- ### Filtering tags
258
-
259
- Filter on a single tag
260
-
261
- ``` yml
262
- pagination:
263
- enabled: true
264
- tag: cool
265
- ```
266
-
267
- Filter on multiple tags
268
-
269
- ``` yml
270
- pagination:
271
- enabled: true
272
- tag: cool, life
273
- ```
274
-
275
- > 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"_
276
-
277
- ### Filtering locales
278
-
279
- 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
280
-
281
- The category page front-matter would look like this
282
-
283
- ``` yml
284
- pagination:
285
- enabled: true
286
- locale: en_US
287
- ```
288
-
289
- Then for the relevant posts, include the `locale` variable in their front-matter
290
-
291
- ``` yml
292
- locale: en_US
293
- ```
294
-
295
- ## Paginate on combination of filters
296
-
297
- Including only posts from categories 'ruby' and 'software' written in English
298
-
299
- ``` yml
300
- pagination:
301
- enabled: true
302
- category: software, ruby
303
- locale: en_US, en_GB, en_WW
304
- ```
305
-
306
- Only showing posts tagged with 'cool' and in category 'cars'
307
-
308
- ``` yml
309
- pagination:
310
- enabled: true
311
- category: cars
312
- tag: cool
313
- ```
314
-
315
- ... and so on and so on
316
-
317
- ## Configuration overrides
318
-
319
- 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
320
-
321
- ``` yml
322
- pagination:
323
- enabled: true
324
- category: cars
325
- permalink: '/cars/:num/'
326
- ```
327
-
328
- Overriding sorting to sort by the post title in ascending order for another paginated page could be done like so
329
-
330
- ``` yml
331
- pagination:
332
- enabled: true
333
- category: ruby
334
- sort_field: 'title'
335
- sort_reverse: false
336
- ```
337
-
338
- ## Advanced Sorting
339
- Sorting can be done by any field that is available in the post front-matter. You can even sort by nested fields.
340
-
341
- > When sorting by nested fields separate the fields with a colon `:` character.
342
-
343
- As an example, assuming all your posts have the following front-matter
344
-
345
- ``` yml
346
- ---
347
- layout: post
348
- author:
349
- name:
350
- first: "John"
351
- last: "Smith"
352
- born: 1960
353
- ---
354
- ```
355
-
356
- You can define pagination sorting on the nested `first` field like so
357
-
358
- ``` yml
359
- ---
360
- layout: page
361
- title: "Authors by first name"
362
- pagination:
363
- enabled: true
364
- sort_field: 'author:name:first'
365
- ---
366
- ```
367
-
368
- To sort by the `born` year in decending order (youngest first)
369
-
370
- ``` yml
371
- ---
372
- layout: page
373
- title: "Authors by birth year"
374
- pagination:
375
- enabled: true
376
- sort_field: 'author:born'
377
- sort_reverse: true
378
- ---
379
- ```
380
-
381
- ## Detecting generated pagination pages
382
-
383
- 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
384
-
385
- ```
386
- {% for my_page in site.pages %}
387
- {% if my_page.title and my_page.autogen == nil %}
388
- <h1>{{ my_page.title | escape }}</h1>
389
- {% endif %}
390
- {% endfor %}
391
- ```
392
- _In this example only pages that have a title and are not auto-generated are included._
393
-
394
- This variable is created and assigned the value `page.autogen = "jekyll-paginate-v2"` by the pagination logic. This way you can detect which pages are auto-generated and by what gem.
395
-
396
- ## Common issues
397
-
398
- ### I keep getting a dependency error when running jekyll serve after installing this gem
399
-
400
- > Dependency Error: Yikes! It looks like you don't have jekyll-paginate-v2 or one of its dependencies installed...
401
-
402
- Check your `Gemfile` in the site root. Ensure that the jekyll-paginate-v2 gem is present in the jekyll_plugins group like the example below. If this group is missing add to the file.
403
-
404
- ``` ruby
405
- group :jekyll_plugins do
406
- gem "jekyll-paginate-v2"
407
- end
408
- ```
409
-
410
- ### I'm getting a bundler error after upgrading the gem (Bundler::GemNotFound)
411
-
412
- > bundler/spec_set.rb:95:in `block in materialize': Could not find jekyll-paginate-v2-1.0.0 in any of the sources (Bundler::GemNotFound)
413
-
414
- Delete your `Gemfile.lock` file and try again.
415
-
416
- ### My pagination pages are not being found (Couldn't find any pagination page. Skipping pagination)
417
-
418
- > Pagination: Is enabled, but I couldn't find any pagination page. Skipping pagination...
419
-
420
- * Ensure that you have the correct minimum front-matter in the pagination pages
421
- ``` yml
422
- pagination:
423
- enabled: true
424
- ```
425
- * You can place pagination logic into either the pages or liquid templates (templates are stored under the `_layouts/` and `_includes/` folders).
426
-
427
- ### My pages are being nested multiple levels deep
428
-
429
- When using `categories` for posts it is advisable to explicitly state a `permalink` structure in your `_config.yml` file.
430
-
431
- ```
432
- permalink: /:year/:month/:title.html
433
- ```
434
-
435
- 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.
436
-
437
- ### My pagination pages are overwriting each others pages
438
- 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
439
-
440
- ``` yml
441
- pagination:
442
- enabled: true
443
- permalink: '/cars/:num/'
444
- ```
445
-
446
- 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.
447
48
 
448
49
  ## Issues / to-be-completed
449
- * A few missing unit-tests
50
+
51
+ * Unit-tests do not cover all critical code paths
450
52
  * No integration tests yet [#2](https://github.com/jekyll/jekyll-paginate/pull/2)
451
53
  * _Exclude_ filter not implemented [#6](https://github.com/jekyll/jekyll-paginate/issues/6)
452
- * Considering adding a feature to auto-generate collection/category/tag/locale pagination pages. In cases where projects have hundreds of tags creating the pages by hand is not a feasible option.
54
+ * Elegant way of collecting and printing debug information during pagination
55
+
56
+
57
+ I welcome all testers and people willing to give me feedback and code reviews.
453
58
 
454
59
  ## Contributing
455
60
 
456
- I currently really need testers for the gem and people willing to give me feedback and code reviews.
61
+ > Although this project is small it has a [code of conduct](CODE_OF_CONDUCT.md) that I hope everyone will do their best to follow when contributing to any aspects of this project. Be it discussions, issue reporting, documentation or programming.
457
62
 
458
- If you don't want to open issues here on Github, you can also send me your feedback by email at [jekyll@sverrirs.com](mailto:jekyll@sverrirs.com).
63
+ If you don't want to open issues here on Github, send me your feedback by email at [jekyll@sverrirs.com](mailto:jekyll@sverrirs.com).
459
64
 
460
65
  1. Fork it ( https://github.com/sverrirs/jekyll-paginate-v2/fork )
461
66
  2. Create your feature branch (`git checkout -b my-new-feature`)