jekyll-paginate-v2 1.5.2 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CODE_OF_CONDUCT.md +12 -0
- data/README-AUTOPAGES.md +84 -0
- data/README-GENERATOR.md +441 -0
- data/README.md +16 -411
- data/jekyll-paginate-v2.gemspec +10 -7
- data/lib/jekyll-paginate-v2.rb +7 -1
- data/lib/jekyll-paginate-v2/autopages/autoPages.rb +77 -0
- data/lib/jekyll-paginate-v2/autopages/defaults.rb +21 -18
- data/lib/jekyll-paginate-v2/autopages/pages/baseAutoPage.rb +60 -0
- data/lib/jekyll-paginate-v2/autopages/pages/categoryAutoPage.rb +28 -0
- data/lib/jekyll-paginate-v2/autopages/pages/collectionAutoPage.rb +28 -0
- data/lib/jekyll-paginate-v2/autopages/pages/tagAutoPage.rb +28 -0
- data/lib/jekyll-paginate-v2/autopages/utils.rb +54 -2
- data/lib/jekyll-paginate-v2/generator/compatibilityUtils.rb +55 -4
- data/lib/jekyll-paginate-v2/generator/paginationGenerator.rb +13 -12
- data/lib/jekyll-paginate-v2/generator/paginationModel.rb +292 -283
- data/lib/jekyll-paginate-v2/generator/paginationPage.rb +23 -20
- data/lib/jekyll-paginate-v2/generator/paginator.rb +6 -9
- data/lib/jekyll-paginate-v2/generator/utils.rb +9 -31
- data/lib/jekyll-paginate-v2/version.rb +2 -2
- data/spec/generator/paginator_spec.rb +8 -7
- data/spec/generator/utils_spec.rb +8 -31
- metadata +19 -18
- data/lib/jekyll-paginate-v2/autopages/autoTagPages.rb +0 -66
@@ -19,9 +19,9 @@ module Jekyll
|
|
19
19
|
#
|
20
20
|
# Returns nothing.
|
21
21
|
def generate(site)
|
22
|
-
|
22
|
+
#begin
|
23
23
|
# Retrieve and merge the pagination configuration from the site yml file
|
24
|
-
default_config =
|
24
|
+
default_config = Jekyll::Utils.deep_merge_hashes(DEFAULT, site.config['pagination'] || {})
|
25
25
|
|
26
26
|
# Compatibility Note: (REMOVE AFTER 2018-01-01)
|
27
27
|
# If the legacy paginate logic is configured then read those values and merge with config
|
@@ -51,7 +51,7 @@ module Jekyll
|
|
51
51
|
|
52
52
|
# Handle deprecation of settings and features
|
53
53
|
if( !default_config['title_suffix' ].nil? )
|
54
|
-
Jekyll.
|
54
|
+
Jekyll::Deprecator.deprecation_message "Pagination: The 'title_suffix' configuration has been deprecated. Please use 'title'. See https://github.com/sverrirs/jekyll-paginate-v2/blob/master/README-GENERATOR.md#site-configuration"
|
55
55
|
end
|
56
56
|
|
57
57
|
Jekyll.logger.debug "Pagination:","Starting"
|
@@ -92,12 +92,7 @@ module Jekyll
|
|
92
92
|
################ 2 ####################
|
93
93
|
# Create the proc that constructs the real-life site page
|
94
94
|
# This is necessary to decouple the code from the Jekyll site object
|
95
|
-
|
96
|
-
template_full_path = File.join(site.source, template_path)
|
97
|
-
template_dir = File.dirname(template_path)
|
98
|
-
|
99
|
-
# Create the Jekyll page entry for the page
|
100
|
-
newpage = PaginationPage.new( site, site.source, template_dir, template_full_path)
|
95
|
+
page_add_lambda = lambda do | newpage |
|
101
96
|
site.pages << newpage # Add the page to the site so that it is generated correctly
|
102
97
|
return newpage # Return the site to the calling code
|
103
98
|
end
|
@@ -125,15 +120,21 @@ module Jekyll
|
|
125
120
|
|
126
121
|
################ 4 ####################
|
127
122
|
# Now create and call the model with the real-life page creation proc and site data
|
128
|
-
model = PaginationModel.new(logging_lambda,
|
123
|
+
model = PaginationModel.new(logging_lambda, page_add_lambda, page_remove_lambda, collection_by_name_lambda)
|
129
124
|
if( default_config['legacy'] ) #(REMOVE AFTER 2018-01-01)
|
125
|
+
Jekyll.logger.warn "Pagination:", "You are running jekyll-paginate backwards compatible pagination logic. Please ignore all earlier warnings displayed related to the old jekyll-paginate gem."
|
130
126
|
all_posts = site.site_payload['site']['posts'].reject { |post| post['hidden'] }
|
131
127
|
model.run_compatability(default_config, all_pages, site_title, all_posts) #(REMOVE AFTER 2018-01-01)
|
132
128
|
else
|
133
|
-
model.run(default_config, all_pages, site_title)
|
129
|
+
count = model.run(default_config, all_pages, site_title)
|
130
|
+
Jekyll.logger.info "Pagination:", "Complete, processed #{count} pagination page(s)"
|
134
131
|
end
|
135
132
|
|
136
|
-
|
133
|
+
#rescue => ex
|
134
|
+
# puts ex.backtrace
|
135
|
+
# raise
|
136
|
+
#end
|
137
|
+
end # function generate
|
137
138
|
end # class PaginationGenerator
|
138
139
|
|
139
140
|
end # module PaginateV2
|
@@ -1,284 +1,293 @@
|
|
1
|
-
module Jekyll
|
2
|
-
module PaginateV2::Generator
|
3
|
-
|
4
|
-
#
|
5
|
-
# The main model for the pagination, handles the orchestration of the pagination and calling all the necessary bits and bobs needed :)
|
6
|
-
#
|
7
|
-
class PaginationModel
|
8
|
-
|
9
|
-
@debug = false # is debug output enabled?
|
10
|
-
@logging_lambda = nil # The lambda to use for logging
|
11
|
-
@
|
12
|
-
@page_remove_lambda = nil # Lambda to remove a page from the site.pages collection
|
13
|
-
@collection_by_name_lambda = nil # Lambda to get all documents/posts in a particular collection (by name)
|
14
|
-
|
15
|
-
# ctor
|
16
|
-
def initialize(logging_lambda,
|
17
|
-
@logging_lambda = logging_lambda
|
18
|
-
@
|
19
|
-
@page_remove_lambda = page_remove_lambda
|
20
|
-
@collection_by_name_lambda = collection_by_name_lambda
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
def run(default_config, site_pages, site_title)
|
25
|
-
# By default if pagination is enabled we attempt to find all index.html pages in the site
|
26
|
-
templates = self.discover_paginate_templates(site_pages)
|
27
|
-
if( templates.size.to_i <= 0 )
|
28
|
-
@logging_lambda.call "Is enabled, but I couldn't find any pagination page. Skipping pagination. "+
|
29
|
-
"Pages must have '
|
30
|
-
return
|
31
|
-
end
|
32
|
-
|
33
|
-
# Now for each template page generate the paginator for it
|
34
|
-
for template in templates
|
35
|
-
# All pages that should be paginated need to include the pagination config element
|
36
|
-
if template.data['pagination'].is_a?(Hash)
|
37
|
-
template_config =
|
38
|
-
|
39
|
-
# Handling deprecation of configuration values
|
40
|
-
self._fix_deprecated_config_features(template_config)
|
41
|
-
|
42
|
-
@debug = template_config['debug'] # Is debugging enabled on the page level
|
43
|
-
|
44
|
-
self._debug_print_config_info(template_config, template.path)
|
45
|
-
|
46
|
-
# Only paginate the template if it is explicitly enabled
|
47
|
-
# requiring this makes the logic simpler as I don't need to determine which index pages
|
48
|
-
# were generated automatically and which weren't
|
49
|
-
if( template_config['enabled'] )
|
50
|
-
if !@debug
|
51
|
-
@logging_lambda.call "found page: "+template.path
|
52
|
-
end
|
53
|
-
|
54
|
-
# Request all documents in all collections that the user has requested
|
55
|
-
all_posts = self.get_docs_in_collections(template_config['collection'])
|
56
|
-
|
57
|
-
# Create the necessary indexes for the posts
|
58
|
-
all_categories = PaginationIndexer.index_posts_by(all_posts, 'categories')
|
59
|
-
all_categories['posts'] = all_posts; # Populate a category for all posts (this is here for backward compatibility, do not use this as it will be decommissioned 2018-01-01)
|
60
|
-
# (this is a default and must not be used in the category system)
|
61
|
-
all_tags = PaginationIndexer.index_posts_by(all_posts, 'tags')
|
62
|
-
all_locales = PaginationIndexer.index_posts_by(all_posts, 'locale')
|
63
|
-
|
64
|
-
# TODO: NOTE!!! This whole request for posts and indexing results could be cached to improve performance, leaving like this for now during testing
|
65
|
-
|
66
|
-
# Now construct the pagination data for this template page
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
#
|
75
|
-
|
76
|
-
#
|
77
|
-
#
|
78
|
-
#
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
@logging_lambda.call "
|
91
|
-
|
92
|
-
"
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
#
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
collection_names = raw_collection_names
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
puts f + "
|
146
|
-
puts f + "
|
147
|
-
puts f + "
|
148
|
-
puts f + "
|
149
|
-
puts f + "
|
150
|
-
puts f + "
|
151
|
-
puts f + "
|
152
|
-
puts f + "
|
153
|
-
|
154
|
-
puts f + "
|
155
|
-
|
156
|
-
puts f + "
|
157
|
-
puts f + "
|
158
|
-
puts f + "
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
puts f + "
|
164
|
-
puts f + " Legacy
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
#
|
179
|
-
#
|
180
|
-
#
|
181
|
-
#
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
#
|
194
|
-
|
195
|
-
#
|
196
|
-
#
|
197
|
-
# site
|
198
|
-
#
|
199
|
-
#
|
200
|
-
#
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
(
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
#
|
244
|
-
|
245
|
-
newpage
|
246
|
-
|
247
|
-
#
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
#
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
#
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
end
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
1
|
+
module Jekyll
|
2
|
+
module PaginateV2::Generator
|
3
|
+
|
4
|
+
#
|
5
|
+
# The main model for the pagination, handles the orchestration of the pagination and calling all the necessary bits and bobs needed :)
|
6
|
+
#
|
7
|
+
class PaginationModel
|
8
|
+
|
9
|
+
@debug = false # is debug output enabled?
|
10
|
+
@logging_lambda = nil # The lambda to use for logging
|
11
|
+
@page_add_lambda = nil # The lambda used to create pages and add them to the site
|
12
|
+
@page_remove_lambda = nil # Lambda to remove a page from the site.pages collection
|
13
|
+
@collection_by_name_lambda = nil # Lambda to get all documents/posts in a particular collection (by name)
|
14
|
+
|
15
|
+
# ctor
|
16
|
+
def initialize(logging_lambda, page_add_lambda, page_remove_lambda, collection_by_name_lambda)
|
17
|
+
@logging_lambda = logging_lambda
|
18
|
+
@page_add_lambda = page_add_lambda
|
19
|
+
@page_remove_lambda = page_remove_lambda
|
20
|
+
@collection_by_name_lambda = collection_by_name_lambda
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def run(default_config, site_pages, site_title)
|
25
|
+
# By default if pagination is enabled we attempt to find all index.html pages in the site
|
26
|
+
templates = self.discover_paginate_templates(site_pages)
|
27
|
+
if( templates.size.to_i <= 0 )
|
28
|
+
@logging_lambda.call "Is enabled, but I couldn't find any pagination page. Skipping pagination. "+
|
29
|
+
"Pages must have 'pagination: enabled: true' in their front-matter for pagination to work.", "warn"
|
30
|
+
return
|
31
|
+
end
|
32
|
+
|
33
|
+
# Now for each template page generate the paginator for it
|
34
|
+
for template in templates
|
35
|
+
# All pages that should be paginated need to include the pagination config element
|
36
|
+
if template.data['pagination'].is_a?(Hash)
|
37
|
+
template_config = Jekyll::Utils.deep_merge_hashes(default_config, template.data['pagination'] || {})
|
38
|
+
|
39
|
+
# Handling deprecation of configuration values
|
40
|
+
self._fix_deprecated_config_features(template_config)
|
41
|
+
|
42
|
+
@debug = template_config['debug'] # Is debugging enabled on the page level
|
43
|
+
|
44
|
+
self._debug_print_config_info(template_config, template.path)
|
45
|
+
|
46
|
+
# Only paginate the template if it is explicitly enabled
|
47
|
+
# requiring this makes the logic simpler as I don't need to determine which index pages
|
48
|
+
# were generated automatically and which weren't
|
49
|
+
if( template_config['enabled'] )
|
50
|
+
if !@debug
|
51
|
+
@logging_lambda.call "found page: "+template.path, 'debug'
|
52
|
+
end
|
53
|
+
|
54
|
+
# Request all documents in all collections that the user has requested
|
55
|
+
all_posts = self.get_docs_in_collections(template_config['collection'])
|
56
|
+
|
57
|
+
# Create the necessary indexes for the posts
|
58
|
+
all_categories = PaginationIndexer.index_posts_by(all_posts, 'categories')
|
59
|
+
all_categories['posts'] = all_posts; # Populate a category for all posts (this is here for backward compatibility, do not use this as it will be decommissioned 2018-01-01)
|
60
|
+
# (this is a default and must not be used in the category system)
|
61
|
+
all_tags = PaginationIndexer.index_posts_by(all_posts, 'tags')
|
62
|
+
all_locales = PaginationIndexer.index_posts_by(all_posts, 'locale')
|
63
|
+
|
64
|
+
# TODO: NOTE!!! This whole request for posts and indexing results could be cached to improve performance, leaving like this for now during testing
|
65
|
+
|
66
|
+
# Now construct the pagination data for this template page
|
67
|
+
self.paginate(template, template_config, site_title, all_posts, all_tags, all_categories, all_locales)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end #for
|
71
|
+
|
72
|
+
# Return the total number of templates found
|
73
|
+
return templates.size.to_i
|
74
|
+
end # function run
|
75
|
+
|
76
|
+
#
|
77
|
+
# This function is here to retain the old compatability logic with the jekyll-paginate gem
|
78
|
+
# no changes should be made to this function and it should be retired and deleted after 2018-01-01
|
79
|
+
# (REMOVE AFTER 2018-01-01)
|
80
|
+
#
|
81
|
+
def run_compatability(legacy_config, site_pages, site_title, all_posts)
|
82
|
+
|
83
|
+
# Decomissioning error
|
84
|
+
if( date = Date.strptime("20180101","%Y%m%d") <= Date.today )
|
85
|
+
raise ArgumentError.new("Legacy jekyll-paginate configuration compatibility mode has expired. Please upgrade to jekyll-paginate-v2 configuration.")
|
86
|
+
end
|
87
|
+
|
88
|
+
# Two month warning or general notification
|
89
|
+
if( date = Date.strptime("20171101","%Y%m%d") <= Date.today )
|
90
|
+
@logging_lambda.call "Legacy pagination logic will stop working on Jan 1st 2018, update your configs before that time.", "warn"
|
91
|
+
else
|
92
|
+
@logging_lambda.call "Detected legacy jekyll-paginate logic running. "+
|
93
|
+
"Please update your configs to use the jekyll-paginate-v2 logic. This compatibility function "+
|
94
|
+
"will stop working after Jan 1st 2018 and your site build will throw an error.", "warn"
|
95
|
+
end
|
96
|
+
|
97
|
+
if template = CompatibilityUtils.template_page(site_pages, legacy_config['legacy_source'], legacy_config['permalink'])
|
98
|
+
CompatibilityUtils.paginate(legacy_config, all_posts, template, @page_add_lambda)
|
99
|
+
else
|
100
|
+
@logging_lambda.call "Legacy pagination is enabled, but I couldn't find " +
|
101
|
+
"an index.html page to use as the pagination page. Skipping pagination.", "warn"
|
102
|
+
end
|
103
|
+
end # function run_compatability (REMOVE AFTER 2018-01-01)
|
104
|
+
|
105
|
+
# Returns the combination of all documents in the collections that are specified
|
106
|
+
# raw_collection_names can either be a list of collections separated by a ',' or ' ' or a single string
|
107
|
+
def get_docs_in_collections(raw_collection_names)
|
108
|
+
if raw_collection_names.is_a?(String)
|
109
|
+
collection_names = raw_collection_names.split(/;|,|\s/)
|
110
|
+
else
|
111
|
+
collection_names = raw_collection_names
|
112
|
+
end
|
113
|
+
|
114
|
+
docs = []
|
115
|
+
# Now for each of the collections get the docs
|
116
|
+
for coll_name in collection_names
|
117
|
+
# Request all the documents for the collection in question, and join it with the total collection
|
118
|
+
docs += @collection_by_name_lambda.call(coll_name.downcase.strip)
|
119
|
+
end
|
120
|
+
|
121
|
+
return docs
|
122
|
+
end
|
123
|
+
|
124
|
+
def _fix_deprecated_config_features(config)
|
125
|
+
keys_to_delete = []
|
126
|
+
|
127
|
+
# As of v1.5.1 the title_suffix is deprecated and 'title' should be used
|
128
|
+
# but only if title has not been defined already!
|
129
|
+
if( !config['title_suffix'].nil? )
|
130
|
+
if( config['title'].nil? )
|
131
|
+
config['title'] = ":title" + config['title_suffix'].to_s # Migrate the old key to title
|
132
|
+
end
|
133
|
+
keys_to_delete << "title_suffix" # Always remove the depricated key if found
|
134
|
+
end
|
135
|
+
|
136
|
+
# Delete the depricated keys
|
137
|
+
config.delete_if{ |k,| keys_to_delete.include? k }
|
138
|
+
end
|
139
|
+
|
140
|
+
def _debug_print_config_info(config, page_path)
|
141
|
+
r = 20
|
142
|
+
f = "Pagination: ".rjust(20)
|
143
|
+
# Debug print the config
|
144
|
+
if @debug
|
145
|
+
puts f + "----------------------------"
|
146
|
+
puts f + "Page: "+page_path.to_s
|
147
|
+
puts f + " Active configuration"
|
148
|
+
puts f + " Enabled: ".ljust(r) + config['enabled'].to_s
|
149
|
+
puts f + " Items per page: ".ljust(r) + config['per_page'].to_s
|
150
|
+
puts f + " Permalink: ".ljust(r) + config['permalink'].to_s
|
151
|
+
puts f + " Title: ".ljust(r) + config['title'].to_s
|
152
|
+
puts f + " Limit: ".ljust(r) + config['limit'].to_s
|
153
|
+
puts f + " Sort by: ".ljust(r) + config['sort_field'].to_s
|
154
|
+
puts f + " Sort reverse: ".ljust(r) + config['sort_reverse'].to_s
|
155
|
+
|
156
|
+
puts f + " Active Filters"
|
157
|
+
puts f + " Collection: ".ljust(r) + config['collection'].to_s
|
158
|
+
puts f + " Category: ".ljust(r) + (config['category'].nil? || config['category'] == "posts" ? "[Not set]" : config['category'].to_s)
|
159
|
+
puts f + " Tag: ".ljust(r) + (config['tag'].nil? ? "[Not set]" : config['tag'].to_s)
|
160
|
+
puts f + " Locale: ".ljust(r) + (config['locale'].nil? ? "[Not set]" : config['locale'].to_s)
|
161
|
+
|
162
|
+
if config['legacy']
|
163
|
+
puts f + " Legacy Paginate Code Enabled"
|
164
|
+
puts f + " Legacy Paginate: ".ljust(r) + config['per_page'].to_s
|
165
|
+
puts f + " Legacy Source: ".ljust(r) + config['legacy_source'].to_s
|
166
|
+
puts f + " Legacy Path: ".ljust(r) + config['paginate_path'].to_s
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def _debug_print_filtering_info(filter_name, before_count, after_count)
|
172
|
+
# Debug print the config
|
173
|
+
if @debug
|
174
|
+
puts "Pagination: ".rjust(20) + " Filtering by: "+filter_name.to_s.ljust(9) + " " + before_count.to_s.rjust(3) + " => " + after_count.to_s
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
#
|
179
|
+
# Rolls through all the pages passed in and finds all pages that have pagination enabled on them.
|
180
|
+
# These pages will be used as templates
|
181
|
+
#
|
182
|
+
# site_pages - All pages in the site
|
183
|
+
#
|
184
|
+
def discover_paginate_templates(site_pages)
|
185
|
+
candidates = []
|
186
|
+
site_pages.select do |page|
|
187
|
+
# If the page has the enabled config set, supports any type of file name html or md
|
188
|
+
if page.data['pagination'].is_a?(Hash) && page.data['pagination']['enabled']
|
189
|
+
candidates << page
|
190
|
+
end
|
191
|
+
end
|
192
|
+
return candidates
|
193
|
+
end # function discover_paginate_templates
|
194
|
+
|
195
|
+
# Paginates the blog's posts. Renders the index.html file into paginated
|
196
|
+
# directories, e.g.: page2/index.html, page3/index.html, etc and adds more
|
197
|
+
# site-wide data.
|
198
|
+
#
|
199
|
+
# site - The Site.
|
200
|
+
# template - The index.html Page that requires pagination.
|
201
|
+
# config - The configuration settings that should be used
|
202
|
+
#
|
203
|
+
def paginate(template, config, site_title, all_posts, all_tags, all_categories, all_locales)
|
204
|
+
# By default paginate on all posts in the site
|
205
|
+
using_posts = all_posts
|
206
|
+
|
207
|
+
# Now start filtering out any posts that the user doesn't want included in the pagination
|
208
|
+
before = using_posts.size.to_i
|
209
|
+
using_posts = PaginationIndexer.read_config_value_and_filter_posts(config, 'category', using_posts, all_categories)
|
210
|
+
self._debug_print_filtering_info('Category', before, using_posts.size.to_i)
|
211
|
+
before = using_posts.size.to_i
|
212
|
+
using_posts = PaginationIndexer.read_config_value_and_filter_posts(config, 'tag', using_posts, all_tags)
|
213
|
+
self._debug_print_filtering_info('Tag', before, using_posts.size.to_i)
|
214
|
+
before = using_posts.size.to_i
|
215
|
+
using_posts = PaginationIndexer.read_config_value_and_filter_posts(config, 'locale', using_posts, all_locales)
|
216
|
+
self._debug_print_filtering_info('Locale', before, using_posts.size.to_i)
|
217
|
+
|
218
|
+
# Apply sorting to the posts if configured, any field for the post is available for sorting
|
219
|
+
if config['sort_field']
|
220
|
+
sort_field = config['sort_field'].to_s
|
221
|
+
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)) }
|
222
|
+
if config['sort_reverse']
|
223
|
+
using_posts.reverse!
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
# Calculate the max number of pagination-pages based on the configured per page value
|
228
|
+
total_pages = Utils.calculate_number_of_pages(using_posts, config['per_page'])
|
229
|
+
|
230
|
+
# If a upper limit is set on the number of total pagination pages then impose that now
|
231
|
+
if config['limit'] && config['limit'].to_i > 0 && config['limit'].to_i < total_pages
|
232
|
+
total_pages = config['limit'].to_i
|
233
|
+
end
|
234
|
+
|
235
|
+
#### BEFORE STARTING REMOVE THE TEMPLATE PAGE FROM THE SITE LIST!
|
236
|
+
@page_remove_lambda.call( template )
|
237
|
+
|
238
|
+
# Now for each pagination page create it and configure the ranges for the collection
|
239
|
+
# This .pager member is a built in thing in Jekyll and defines the paginator implementation
|
240
|
+
# Simpy override to use mine
|
241
|
+
(1..total_pages).each do |cur_page_nr|
|
242
|
+
|
243
|
+
# 1. Create the in-memory page
|
244
|
+
# External Proc call to create the actual page for us (this is passed in when the pagination is run)
|
245
|
+
newpage = PaginationPage.new( template, true )
|
246
|
+
|
247
|
+
# 2. Create the url for the in-memory page (calc permalink etc), construct the title, set all page.data values needed
|
248
|
+
paginated_page_url = config['permalink']
|
249
|
+
first_index_page_url = ""
|
250
|
+
if template.data['permalink']
|
251
|
+
first_index_page_url = template.data['permalink']
|
252
|
+
else
|
253
|
+
first_index_page_url = template.dir
|
254
|
+
end
|
255
|
+
paginated_page_url = File.join(first_index_page_url, paginated_page_url)
|
256
|
+
|
257
|
+
# 3. Create the pager logic for this page, pass in the prev and next page numbers, assign pager to in-memory page
|
258
|
+
newpage.pager = Paginator.new( config['per_page'], first_index_page_url, paginated_page_url, using_posts, cur_page_nr, total_pages)
|
259
|
+
|
260
|
+
# Create the url for the new page, make sure we prepend any permalinks that are defined in the template page before
|
261
|
+
newpage.set_url(File.join(newpage.pager.page_path, 'index.html'))
|
262
|
+
if( template.data['permalink'] )
|
263
|
+
newpage.data['permalink'] = newpage.pager.page_path
|
264
|
+
end
|
265
|
+
|
266
|
+
# Transfer the title across to the new page
|
267
|
+
if( !template.data['title'] )
|
268
|
+
tmp_title = site_title
|
269
|
+
else
|
270
|
+
tmp_title = template.data['title']
|
271
|
+
end
|
272
|
+
# If the user specified a title suffix to be added then let's add that to all the pages except the first
|
273
|
+
if( cur_page_nr > 1 && config.has_key?('title') )
|
274
|
+
newpage.data['title'] = "#{Utils.format_page_title(config['title'], tmp_title, cur_page_nr, total_pages)}"
|
275
|
+
else
|
276
|
+
newpage.data['title'] = tmp_title
|
277
|
+
end
|
278
|
+
|
279
|
+
# Signals that this page is automatically generated by the pagination logic
|
280
|
+
# (we don't do this for the first page as it is there to mask the one we removed)
|
281
|
+
if cur_page_nr > 1
|
282
|
+
newpage.data['autogen'] = "jekyll-paginate-v2"
|
283
|
+
end
|
284
|
+
|
285
|
+
# Add the page to the site
|
286
|
+
@page_add_lambda.call( newpage )
|
287
|
+
end
|
288
|
+
end # function paginate
|
289
|
+
|
290
|
+
end # class PaginationV2
|
291
|
+
|
292
|
+
end # module PaginateV2
|
284
293
|
end # module Jekyll
|