jekyll-paginate-v2 1.9.4 → 2.0.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: 59ee73bfdddde665bfcac280629290ca03b809bc
4
- data.tar.gz: a9534eca1fc37f499b33e8f4a4c6cefaf6b67adf
3
+ metadata.gz: 5b1be5a3a418704b6d5798054c310cb0d1db73c8
4
+ data.tar.gz: a0861fb2289e24c3ebc6d0047a9f4e55c7e8b866
5
5
  SHA512:
6
- metadata.gz: 15f6a51f471f9950952f9ebbe45f4306dbd7c15ea70a95849d74f73c9b9905a44473d4284bd46aa30129ee13c71f630387326d97d7524f0ffeb8787f77d32ad1
7
- data.tar.gz: 97299085a18024745768845f073e8d2a3d8df2ba41f6d07c3298dd15511d6dba6d7086cb603288b57fa424370b6de73ff52e42cc250dc80bd5f3e99d8820aada
6
+ metadata.gz: 6ac0fae0864bed484368ce0dd83645e177809c0a90c0fb8a1b55536cb15ecd693bbe9dcd058d90c7e797f1ba834ba0ba7fa2c8ef6464f6ccf73929e1a4c2254f
7
+ data.tar.gz: b7bf4594ed5718a301b49a118f4b040627f4705d601ef52cb0e79223c9b12436c900637a83048bdeb41bfaaca771618199eb2fe617b9f61c6f9f65baaac73d66
@@ -100,5 +100,42 @@ An example of this can be found in [examples/03-tags/_layouts/autopage_collectio
100
100
  ### Title should not contain pagination macros
101
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
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/jekyll-paginate-v2/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
+
103
140
  ## Common issues
104
- _None reported so far_
141
+ _None reported so far_
@@ -271,6 +271,36 @@ pagination:
271
271
  category: software, ruby
272
272
  ```
273
273
 
274
+ You may use also use `categories` instead:
275
+
276
+ ``` yml
277
+ pagination:
278
+ enabled: true
279
+ categories:
280
+ - software
281
+ - ruby
282
+ ```
283
+
284
+ **Note:** Do *not* use `categories` as follows:
285
+
286
+ ``` yml
287
+ categories: programming language, ruby
288
+ ```
289
+
290
+ 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
291
+
292
+ ``` yml
293
+ category: programming language, ruby
294
+ ```
295
+
296
+ or
297
+
298
+ ``` yml
299
+ categories:
300
+ - programming language
301
+ - ruby
302
+ ```
303
+
274
304
  > 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.
275
305
 
276
306
  ### Filtering tags
@@ -291,6 +321,16 @@ pagination:
291
321
  tag: cool, life
292
322
  ```
293
323
 
324
+ As with categories, you may also use the following syntax:
325
+
326
+ ``` yml
327
+ pagination:
328
+ enabled: true
329
+ tags:
330
+ - cool
331
+ - life
332
+ ```
333
+
294
334
  > 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"_
295
335
 
296
336
  ### Filtering locales
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Jekyll::Paginate V2
2
2
 
3
- Pagination gem built specially for Jekyll 3 and newer that is fully backwards compatable and serves as an enhanced replacement for the previously built-in [jekyll-paginate gem](https://github.com/jekyll/jekyll-paginate). View it on [rubygems.org](https://rubygems.org/gems/jekyll-paginate-v2).
3
+ Pagination gem built specially for Jekyll 3 and newer that is fully backwards compatible and serves as an enhanced replacement for the previously built-in [jekyll-paginate gem](https://github.com/jekyll/jekyll-paginate). View it on [rubygems.org](https://rubygems.org/gems/jekyll-paginate-v2).
4
4
 
5
5
  [![Gem](https://img.shields.io/gem/v/jekyll-paginate-v2.svg)](https://rubygems.org/gems/jekyll-paginate-v2)
6
6
  [![Join the chat at https://gitter.im/jekyll-paginate-v2/Lobby](https://badges.gitter.im/jekyll-paginate-v2/Lobby.svg)](https://gitter.im/jekyll-paginate-v2/Lobby)
@@ -10,7 +10,7 @@ Pagination gem built specially for Jekyll 3 and newer that is fully backwards co
10
10
  [![security](https://hakiri.io/github/sverrirs/jekyll-paginate-v2/master.svg)](https://hakiri.io/github/sverrirs/jekyll-paginate-v2/master)
11
11
  [![Gem](https://img.shields.io/gem/dt/jekyll-paginate-v2.svg)](https://rubygems.org/gems/jekyll-paginate-v2)
12
12
 
13
- Reach me at the [project issues](https://github.com/sverrirs/jekyll-paginate-v2/issues) section or via email at [jekyll@sverrirs.com](mailto:jekyll@sverrirs.com), you can also get in touch on the project's [Glitter chat room](https://gitter.im/jekyll-paginate-v2/Lobby).
13
+ Reach me at the [project issues](https://github.com/sverrirs/jekyll-paginate-v2/issues) section or via email at [jekyll@sverrirs.com](mailto:jekyll@sverrirs.com), you can also get in touch on the project's [Gitter chat room](https://gitter.im/jekyll-paginate-v2/Lobby).
14
14
 
15
15
  > 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)).
16
16
 
@@ -39,6 +39,10 @@ Now you're ready to run `jekyll serve` and your paginated files should be genera
39
39
 
40
40
  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.
41
41
 
42
+ > :warning: Please note that this plugin is currently NOT supported by GitHub pages. Here is a [list of all plugins supported](https://pages.github.com/versions/). There is work underway to try to get it added it but until then please follow [this GitHub guide](https://help.github.com/articles/adding-jekyll-plugins-to-a-github-pages-site/) to enable it or use [Travis CI](https://ayastreb.me/deploy-jekyll-to-github-pages-with-travis-ci/).
43
+
44
+ > GitLab supposedly supports [any plugin](https://about.gitlab.com/comparison/gitlab-pages-vs-github-pages.html).
45
+
42
46
 
43
47
  ## Pagination Generator
44
48
 
@@ -11,6 +11,7 @@ module Jekyll
11
11
  # this function received the pagination config hash and manipulates it
12
12
  set_autopage_data_lambda = lambda do | in_config |
13
13
  in_config['category'] = category
14
+ in_config['collection'] = site.collections.keys
14
15
  end
15
16
 
16
17
  get_autopage_permalink_lambda = lambda do |permalink_pattern|
@@ -11,6 +11,7 @@ module Jekyll
11
11
  # this function received the pagination config hash and manipulates it
12
12
  set_autopage_data_lambda = lambda do | config |
13
13
  config['tag'] = tag
14
+ config['collection'] = site.collections.keys
14
15
  end
15
16
 
16
17
  get_autopage_permalink_lambda = lambda do |permalink_pattern|
@@ -32,7 +32,7 @@ module Jekyll
32
32
  def self.collect_all_docs(site_collections)
33
33
  coll = []
34
34
  site_collections.each do |coll_name, coll_data|
35
- if !coll_data.nil?
35
+ if !coll_data.nil?
36
36
  coll += coll_data.docs.select { |doc| !doc.data.has_key?('pagination') }.each{ |doc| doc.data['__coll'] = coll_name } # Exclude all pagination pages and then for every page store it's collection name
37
37
  end
38
38
  end
@@ -49,25 +49,21 @@ module Jekyll
49
49
  next if post.data[index_key].nil?
50
50
  next if post.data[index_key].size <= 0
51
51
  next if post.data[index_key].to_s.strip.length == 0
52
-
52
+
53
53
  # Only tags and categories come as premade arrays, locale does not, so convert any data
54
54
  # elements that are strings into arrays
55
55
  post_data = post.data[index_key]
56
56
  if post_data.is_a?(String)
57
57
  post_data = post_data.split(/;|,|\s/)
58
58
  end
59
-
59
+
60
60
  post_data.each do |key|
61
- key = key.strip
62
- # If the key is a delimetered list of values
63
- # (meaning the user didn't use an array but a string with commas)
64
- key.split(/;|,/).each do |raw_k_split|
65
- k_split = raw_k_split.to_s.downcase.strip #Clean whitespace and junk
66
- if !index.has_key?(k_split)
67
- # Need to store the original key value here so that I can present it to the users as a page variable they can use (unmodified, e.g. tags not being 'sci-fi' but "Sci-Fi")
68
- # Also, only interested in storing all the keys not the pages in this case
69
- index[k_split.to_s] = [k_split.to_s, raw_k_split.to_s]
70
- end
61
+ key = key.to_s.strip
62
+ processed_key = key.downcase #Clean whitespace and junk
63
+ if !index.has_key?(processed_key)
64
+ # Need to store the original key value here so that I can present it to the users as a page variable they can use (unmodified, e.g. tags not being 'sci-fi' but "Sci-Fi")
65
+ # Also, only interested in storing all the keys not the pages in this case
66
+ index[processed_key] = [processed_key, key]
71
67
  end
72
68
  end
73
69
  end
@@ -5,6 +5,7 @@ module Jekyll
5
5
  DEFAULT = {
6
6
  'enabled' => false,
7
7
  'collection' => 'posts',
8
+ 'offset' => 0, # Supports skipping x number of posts from the beginning of the post list
8
9
  'per_page' => 10,
9
10
  'permalink' => '/page:num/', # Supports :num as customizable elements
10
11
  'title' => ':title - page :num', # Supports :num as customizable elements
@@ -66,24 +66,47 @@ module Jekyll
66
66
  return nil if posts.nil?
67
67
  return nil if source_posts.nil? # If the source is empty then simply don't do anything
68
68
  return posts if config.nil?
69
- return posts if !config.has_key?(config_key)
70
- return posts if config[config_key].nil?
69
+
70
+ plural_key = Utils.plural(config_key)
71
+
72
+ return posts if !config.has_key?(config_key) && !config.has_key?(plural_key)
73
+ return posts if config[config_key].nil? && config[plural_key].nil?
71
74
 
72
75
  # Get the filter values from the config (this is the cat/tag/locale values that should be filtered on)
73
- config_value = config[config_key]
74
76
 
75
- # If we're dealing with a delimitered string instead of an array then let's be forgiving
76
- if( config_value.is_a?(String))
77
- config_value = config_value.split(/;|,/)
77
+ if config[config_key].is_a?(Hash) || config[plural_key].is_a?(Hash)
78
+ # { values: [..], matching: any|all }
79
+ config_hash = config[config_key].is_a?(Hash) ? config[config_key] : config[plural_key]
80
+ config_value = Utils.config_values(config_hash, 'value')
81
+ matching = config_hash['matching'] || 'all'
82
+ else
83
+ # Default array syntax
84
+ config_value = Utils.config_values(config, config_key)
85
+ matching = 'all'
78
86
  end
79
87
 
80
- # Now for all filter values for the config key, let's remove all items from the posts that
81
- # aren't common for all collections that the user wants to filter on
82
- config_value.each do |key|
83
- key = key.to_s.downcase.strip
84
- posts = PaginationIndexer.intersect_arrays(posts, source_posts[key])
88
+ matching = matching.to_s.downcase.strip
89
+
90
+ # Filter on any/all specified categories, etc.
91
+
92
+ if matching == "all"
93
+ # Now for all filter values for the config key, let's remove all items from the posts that
94
+ # aren't common for all collections that the user wants to filter on
95
+ config_value.each do |key|
96
+ key = key.to_s.downcase.strip
97
+ posts = PaginationIndexer.intersect_arrays(posts, source_posts[key])
98
+ end
99
+
100
+ elsif matching == "any"
101
+ # "or" filter: Remove posts that don't have at least one required key
102
+ posts.delete_if { |post|
103
+ post_config = Utils.config_values(post.data, config_key)
104
+ (config_value & post_config).empty?
105
+ }
106
+
107
+ # else no filter
85
108
  end
86
-
109
+
87
110
  # The fully filtered final post list
88
111
  return posts
89
112
  end #function read_config_value_and_filter_posts
@@ -158,6 +158,7 @@ module Jekyll
158
158
 
159
159
  puts f + " Active Filters"
160
160
  puts f + " Collection: ".ljust(r) + config['collection'].to_s
161
+ puts f + " Offset: ".ljust(r) + config['offset'].to_s
161
162
  puts f + " Category: ".ljust(r) + (config['category'].nil? || config['category'] == "posts" ? "[Not set]" : config['category'].to_s)
162
163
  puts f + " Tag: ".ljust(r) + (config['tag'].nil? ? "[Not set]" : config['tag'].to_s)
163
164
  puts f + " Locale: ".ljust(r) + (config['locale'].nil? ? "[Not set]" : config['locale'].to_s)
@@ -243,6 +244,10 @@ module Jekyll
243
244
 
244
245
  using_posts.sort!{ |a,b| Utils.sort_values(Utils.sort_get_post_data(a.data, sort_field), Utils.sort_get_post_data(b.data, sort_field)) }
245
246
 
247
+ # Remove the first x entries
248
+ offset_post_count = [0, config['offset'].to_i].max
249
+ using_posts.pop(offset_post_count)
250
+
246
251
  if config['sort_reverse']
247
252
  using_posts.reverse!
248
253
  end
@@ -13,12 +13,24 @@ module Jekyll
13
13
  @site = page_to_copy.site
14
14
  @base = ''
15
15
  @url = ''
16
- @name = index_pageandext.nil? ? 'index.html' : index_pageandext
16
+ if cur_page_nr == 1
17
+ @dir = File.dirname(page_to_copy.dir)
18
+ @name = page_to_copy.name
19
+ else
20
+ @name = index_pageandext.nil? ? 'index.html' : index_pageandext
21
+ end
17
22
 
18
23
  self.process(@name) # Creates the basename and ext member values
19
24
 
20
- # Only need to copy the data part of the page as it already contains the layout information
21
- self.data = Jekyll::Utils.deep_merge_hashes( page_to_copy.data, {} )
25
+ # Copy page data over site defaults
26
+ defaults = @site.frontmatter_defaults.all(page_to_copy.relative_path, type)
27
+ self.data = Jekyll::Utils.deep_merge_hashes(defaults, page_to_copy.data)
28
+
29
+ if defaults.has_key?('permalink')
30
+ self.data['permalink'] = Jekyll::URL.new(:template => defaults['permalink'], :placeholders => self.url_placeholders).to_s
31
+ @use_permalink_for_url = true
32
+ end
33
+
22
34
  if !page_to_copy.data['autopage']
23
35
  self.content = page_to_copy.content
24
36
  else
@@ -41,7 +53,7 @@ module Jekyll
41
53
  end
42
54
 
43
55
  def set_url(url_value)
44
- @url = url_value
56
+ @url = @use_permalink_for_url ? self.data['permalink'] : url_value
45
57
  end
46
58
  end # class PaginationPage
47
59
 
@@ -135,6 +135,27 @@ module Jekyll
135
135
  return url
136
136
  end
137
137
 
138
+ # Constructs the plural for a key
139
+ def self.plural(config_key)
140
+ (config_key =~ /s$/) ? config_key :
141
+ (config_key.dup.sub!(/y$/, 'ies') || "#{config_key}s")
142
+ end
143
+
144
+ # Converts a string or array to a downcased, stripped array
145
+ def self.config_array(config, key, keepcase = nil)
146
+ [ config[key] ].flatten.compact.uniq.map { |c|
147
+ c.split(/[,;]\s*/).map { |v|
148
+ keepcase ? v.to_s.strip : v.to_s.downcase.strip
149
+ }
150
+ }.flatten.uniq
151
+ end
152
+
153
+ # Merges singular and plural config values into an array
154
+ def self.config_values(config, key, keepcase = nil)
155
+ singular = config_array(config, key, keepcase)
156
+ plural = config_array(config, plural(key), keepcase)
157
+ [ singular, plural ].flatten.uniq
158
+ end
138
159
  end
139
160
 
140
161
  end # module PaginateV2
@@ -1,8 +1,8 @@
1
1
  module Jekyll
2
2
  module PaginateV2
3
- VERSION = "1.9.4"
3
+ VERSION = "2.0.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.9.4 -m "Gem v1.9.4"
5
+ # git tag -a v2.0.0 -m "Gem v2.0.0"
6
6
  # git push origin --tags
7
7
  # Yanking a published Gem
8
8
  # gem yank jekyll-paginate-v2 -v VERSION
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.9.4
4
+ version: 2.0.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: 2018-01-24 00:00:00.000000000 Z
11
+ date: 2018-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll