jekyll-paginate-v2 1.6.1 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49eff43d9fc82a1291afa41a9375f5e4892dd977
4
- data.tar.gz: 9446fed7b472bb42b50d16f0e4f718aa38fe220d
3
+ metadata.gz: 520aefbd27b59fcb86fcaca7871c693295bafb16
4
+ data.tar.gz: 3e45a7ccc457134a43ee81520dc0f32971c9989d
5
5
  SHA512:
6
- metadata.gz: 6ed1b856077d5f7fb1ccd9e3839adf8264167ac2a09b73b095b1d54157929ad0d8df283aadfcb4edccb8993a97bd6556ba909f6a703d6aa6c1391a4b459ece33
7
- data.tar.gz: 9da8d889d46921e8d792399da5be7ee832691a1f1d823ee178f351a60e6428860f38d0e5d5c13fba4cb279c19b9fce82c3a6b796f0a7a221fc373f2eb626bff9
6
+ metadata.gz: 31e6855bc99cd94c7160da6e5926046f7cb32b783bd177c9b5ef1d3d38b989063746df296a3909159e3fbc43d9285202d424d165ef639c0187c002828b8ff332
7
+ data.tar.gz: 734e0a050c950f4535c49eb115009f65c509ecd20ce8c1c95b99b27fa535bef19f8a990457edd8a9e1207184004f617d84e416385bf1602c73af28470af51532
@@ -22,6 +22,7 @@ The **Generator** forms the core of the pagination logic. It is responsible for
22
22
  * [How to paginate on combination of filters](#paginate-on-combination-of-filters)
23
23
  * [Overriding site configuration](#configuration-overrides)
24
24
  * [Advanced Sorting](#advanced-sorting)
25
+ * [Creating Pagination Trails](#creating-pagination-trails)
25
26
  * [How to detect auto-generated pages](#detecting-generated-pagination-pages)
26
27
  * [Formatting page titles](#formatting-page-titles)
27
28
  * [Common issues](#common-issues)
@@ -79,6 +80,14 @@ pagination:
79
80
  # 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 )
80
81
  locale: ''
81
82
 
83
+ # Optional,omit or set both before and after to zero to disable.
84
+ # Controls how the pagination trail for the paginated pages look like.
85
+ # this feature enables the user to display a <prev, 1, 2, 3, 4, 5, next> pagination trail on their page
86
+ # By default this feature produces two pages before and two pages after the current page (total of 5 pages)
87
+ trail:
88
+ before: 2
89
+ after: 2
90
+
82
91
  ############################################################
83
92
  ```
84
93
 
@@ -356,6 +365,58 @@ pagination:
356
365
  ---
357
366
  ```
358
367
 
368
+ ## Creating Pagination Trails
369
+
370
+ <p align="center">
371
+ <img src="https://raw.githubusercontent.com/sverrirs/jekyll-paginate-v2/master/res/pagination-trails.png" width="59" />
372
+ </p>
373
+
374
+ 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.
375
+
376
+ ``` yml
377
+ pagination:
378
+ trail:
379
+ before: 2 # The number of links before the current page
380
+ after: 2 # The number of links after the current page
381
+ ```
382
+
383
+ Your layout file would then have to include code similar to the following to generate the correct HTML structure
384
+
385
+ ``` HTML
386
+ {% if paginator.page_trail %}
387
+ {% for trail in paginator.page_trail %}
388
+ <li>
389
+ <a href="{{ trail.path | prepend: site.baseurl }}" title="{{trail.title}}">{{ trail.num }}</a>
390
+ </li>
391
+ {% endfor %}
392
+ {% endif %}
393
+ ```
394
+
395
+ The `trail` value exposes three properties:
396
+ * `num`: The number of the page
397
+ * `path`: The path to the page
398
+ * `title`: The title of the page
399
+
400
+ The algorithm will always attempt to keep the same trail length for all pages (`trail length = before + after + 1`).
401
+ Example when on page 4 the trail for the configuration above would look like this
402
+
403
+ <p align="center">
404
+ <img src="https://raw.githubusercontent.com/sverrirs/jekyll-paginate-v2/master/res/pagination-trails-p4.png" />
405
+ </p>
406
+
407
+ Different number of before and after trail links can be specified. Below is an example of how this yml config would look like when on the same page 4
408
+
409
+ ``` yml
410
+ pagination:
411
+ trail:
412
+ before: 1
413
+ after: 3
414
+ ```
415
+
416
+ <p align="center">
417
+ <img src="https://raw.githubusercontent.com/sverrirs/jekyll-paginate-v2/master/res/pagination-trails-p4-b1a3.png" />
418
+ </p>
419
+
359
420
  ## Detecting generated pagination pages
360
421
 
361
422
  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
@@ -12,6 +12,10 @@ module Jekyll
12
12
  'sort_reverse' => false,
13
13
  'sort_field' => 'date',
14
14
  'limit' => 0, # Limit how many content objects to paginate (default: 0, means all)
15
+ 'trail' => {
16
+ 'before' => 0, # Limits how many links to show before the current page in the pagination trail (0, means off, default: 0)
17
+ 'after' => 0, # Limits how many links to show after the current page in the pagination trail (0 means off, default: 0)
18
+ },
15
19
  'debug' => false, # Turns on debug output for the gem
16
20
  'legacy' => false # Internal value, do not use (will be removed after 2018-01-01)
17
21
  }
@@ -235,6 +235,9 @@ module Jekyll
235
235
  #### BEFORE STARTING REMOVE THE TEMPLATE PAGE FROM THE SITE LIST!
236
236
  @page_remove_lambda.call( template )
237
237
 
238
+ # list of all newly created pages
239
+ newpages = []
240
+
238
241
  # Now for each pagination page create it and configure the ranges for the collection
239
242
  # This .pager member is a built in thing in Jekyll and defines the paginator implementation
240
243
  # Simpy override to use mine
@@ -284,7 +287,38 @@ module Jekyll
284
287
 
285
288
  # Add the page to the site
286
289
  @page_add_lambda.call( newpage )
287
- end
290
+
291
+ # Store the page in an internal list for later referencing if we need to generate a pagination number path later on
292
+ newpages << newpage
293
+ end #each.do total_pages
294
+
295
+ # Now generate the pagination number path, e.g. so that the users can have a prev 1 2 3 4 5 next structure on their page
296
+ # simplest is to include all of the links to the pages preceeding the current one
297
+ # (e.g for page 1 you get the list 2, 3, 4.... and for page 2 you get the list 3,4,5...)
298
+ if( config['trail'] && !config['trail'].nil? && newpages.size.to_i > 1 )
299
+ trail_before = [config['trail']['before'].to_i, 0].max
300
+ trail_after = [config['trail']['after'].to_i, 0].max
301
+ trail_length = trail_before + trail_after + 1
302
+
303
+ if( trail_before > 0 || trail_after > 0 )
304
+ newpages.select do | npage |
305
+ idx_start = [ npage.pager.page - trail_before - 1, 0].max # Selecting the beginning of the trail
306
+ idx_end = [idx_start + trail_length, newpages.size.to_i].min # Selecting the end of the trail
307
+
308
+ # Always attempt to maintain the max total of <trail_length> pages in the trail (it will look better if the trail doesn't shrink)
309
+ if( idx_end - idx_start < trail_length )
310
+ # Attempt to pad the beginning if we have enough pages
311
+ idx_start = [idx_start - ( trail_length - (idx_end - idx_start) ), 0].max # Never go beyond the zero index
312
+ end
313
+
314
+ # Convert the newpages array into a two dimensional array that has [index, page_url] as items
315
+ #puts( "Trail created for page #{npage.pager.page} (idx_start:#{idx_start} idx_end:#{idx_end})")
316
+ npage.pager.page_trail = newpages[idx_start...idx_end].each_with_index.map {|ipage,idx| PageTrail.new(idx_start+idx+1, ipage.pager.page_path, ipage.data['title'])}
317
+ #puts( npage.pager.page_trail )
318
+ end #newpages.select
319
+ end #if trail_before / trail_after
320
+ end # if config['trail']
321
+
288
322
  end # function paginate
289
323
 
290
324
  end # class PaginationV2
@@ -6,7 +6,15 @@ module Jekyll
6
6
  #
7
7
  class Paginator
8
8
  attr_reader :page, :per_page, :posts, :total_posts, :total_pages,
9
- :previous_page, :previous_page_path, :next_page, :next_page_path, :page_path
9
+ :previous_page, :previous_page_path, :next_page, :next_page_path, :page_path, :page_trail
10
+
11
+ def page_trail
12
+ @page_trail
13
+ end
14
+
15
+ def page_trail=(page_array)
16
+ @page_trail = page_array
17
+ end
10
18
 
11
19
  # Initialize a new Paginator.
12
20
  #
@@ -45,11 +53,32 @@ module Jekyll
45
53
  'previous_page' => previous_page,
46
54
  'previous_page_path' => previous_page_path,
47
55
  'next_page' => next_page,
48
- 'next_page_path' => next_page_path
56
+ 'next_page_path' => next_page_path,
57
+ 'page_trail' => page_trail
49
58
  }
50
59
  end
51
60
 
52
61
  end # class Paginator
53
62
 
63
+ # Small utility class that handles individual pagination trails
64
+ # and makes them easier to work with in Liquid
65
+ class PageTrail
66
+ attr_reader :num, :path, :title
67
+
68
+ def initialize( num, path, title )
69
+ @num = num
70
+ @path = path
71
+ @title = title
72
+ end #func initialize
73
+
74
+ def to_liquid
75
+ {
76
+ 'num' => num,
77
+ 'path' => path+"index.html",
78
+ 'title' => title
79
+ }
80
+ end
81
+ end #class PageTrail
82
+
54
83
  end # module PaginateV2
55
84
  end # module Jekyll
@@ -1,8 +1,8 @@
1
1
  module Jekyll
2
2
  module PaginateV2
3
- VERSION = "1.6.1"
3
+ VERSION = "1.7.0"
4
4
  # When modifying remember to issue a new tag command in git before committing, then push the new tag
5
- # git tag -a v1.6.1 -m "Gem v1.6.1"
5
+ # git tag -a v1.7.0 -m "Gem v1.7.0"
6
6
  # git push origin --tags
7
7
  end # module PaginateV2
8
8
  end # module Jekyll
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-paginate-v2
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sverrir Sigmundarson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-24 00:00:00.000000000 Z
11
+ date: 2017-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll