bridgetown-paginate 0.8.1 → 0.9.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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d6aa1e6cf2b4880395481df0e3925fbe91d7287d0e522d359ac4ffcc0081620
|
4
|
+
data.tar.gz: c00d22eb1292f72a25d1699cecf44d53d97c1668371316816eceb378f3c7e47d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a589e35afb76a43eb0d0b32e498f0431c1ad2b4511c616f2128ae06c0df62c1db543cc4bbfcc712db72f143e553dd6a67d2f93841102d9e22e2b4468ddbf2e6
|
7
|
+
data.tar.gz: 73785fe0c2d0327519b170d71b54f77231fabb2e38a227f6f52bf0afcf542fdd82afb36ca22194eacea6dc115e26c64521ca843a8afd03b1649537d585caa805
|
@@ -27,7 +27,8 @@ module Bridgetown
|
|
27
27
|
|
28
28
|
# If disabled then simply quit
|
29
29
|
unless default_config["enabled"]
|
30
|
-
Bridgetown.logger.info "Pagination:", "
|
30
|
+
Bridgetown.logger.info "Pagination:", "disabled. Enable in site config" \
|
31
|
+
" with pagination:\\n enabled: true"
|
31
32
|
return
|
32
33
|
end
|
33
34
|
|
@@ -16,6 +16,9 @@ module Bridgetown
|
|
16
16
|
return nil if all_documents.nil?
|
17
17
|
return all_documents if index_key.nil?
|
18
18
|
|
19
|
+
# Where queries are a key/value pair, so grab the first key element
|
20
|
+
index_key = index_key[0] if index_key.is_a?(Array)
|
21
|
+
|
19
22
|
index = {}
|
20
23
|
all_documents.each do |document|
|
21
24
|
next if document.data.nil?
|
@@ -84,6 +87,9 @@ module Bridgetown
|
|
84
87
|
# values that should be filtered on)
|
85
88
|
config_value = config[config_key]
|
86
89
|
|
90
|
+
# Use the second key/value element if it's a "where query"
|
91
|
+
config_value = config_value[1] if config_key == "where_query"
|
92
|
+
|
87
93
|
# If we're dealing with a delimitered string instead of an array then
|
88
94
|
# let's be forgiving
|
89
95
|
config_value = config_value.split(%r!;|,!) if config_value.is_a?(String)
|
@@ -91,6 +97,8 @@ module Bridgetown
|
|
91
97
|
# Now for all filter values for the config key, let's remove all items
|
92
98
|
# from the documents that aren't common for all collections that the
|
93
99
|
# user wants to filter on
|
100
|
+
# TODO: right now this is an "AND" operation if multiple keys are present.
|
101
|
+
# Should offer the ability to do an OR operation instead.
|
94
102
|
config_value.each do |key|
|
95
103
|
key = key.to_s.downcase.strip
|
96
104
|
documents = PaginationIndexer.intersect_arrays(documents, source_documents[key])
|
@@ -30,14 +30,14 @@ module Bridgetown
|
|
30
30
|
@collection_by_name_lambda = collection_by_name_lambda
|
31
31
|
end
|
32
32
|
|
33
|
+
# rubocop:disable Metrics/BlockLength
|
33
34
|
def run(default_config, site_pages, site_title)
|
34
35
|
# By default if pagination is enabled we attempt to find all index.html
|
35
36
|
# pages in the site
|
36
37
|
templates = discover_paginate_templates(site_pages)
|
37
38
|
if templates.size.to_i <= 0
|
38
|
-
@logging_lambda.call "
|
39
|
-
"
|
40
|
-
" in their front-matter for pagination to work.", "warn"
|
39
|
+
@logging_lambda.call "is enabled in the config, but no paginated pages found." \
|
40
|
+
" Add 'pagination:\\n enabled: true' to the front-matter of a page.", "warn"
|
41
41
|
return
|
42
42
|
end
|
43
43
|
|
@@ -71,6 +71,21 @@ module Bridgetown
|
|
71
71
|
all_tags = PaginationIndexer.index_documents_by(all_posts, "tags")
|
72
72
|
all_locales = PaginationIndexer.index_documents_by(all_posts, "locale")
|
73
73
|
|
74
|
+
# Load in custom query index, if specified
|
75
|
+
all_where_matches = if template_config["where_query"]
|
76
|
+
PaginationIndexer.index_documents_by(
|
77
|
+
all_posts, template_config["where_query"]
|
78
|
+
)
|
79
|
+
end
|
80
|
+
|
81
|
+
documents_payload = {
|
82
|
+
posts: all_posts,
|
83
|
+
tags: all_tags,
|
84
|
+
categories: all_categories,
|
85
|
+
locales: all_locales,
|
86
|
+
where_matches: all_where_matches,
|
87
|
+
}
|
88
|
+
|
74
89
|
# TODO: NOTE!!! This whole request for posts and indexing results
|
75
90
|
# could be cached to improve performance, leaving like this for
|
76
91
|
# now during testing
|
@@ -80,10 +95,7 @@ module Bridgetown
|
|
80
95
|
template,
|
81
96
|
template_config,
|
82
97
|
site_title,
|
83
|
-
|
84
|
-
all_tags,
|
85
|
-
all_categories,
|
86
|
-
all_locales
|
98
|
+
documents_payload
|
87
99
|
)
|
88
100
|
end
|
89
101
|
end
|
@@ -92,6 +104,7 @@ module Bridgetown
|
|
92
104
|
# Return the total number of templates found
|
93
105
|
templates.size.to_i
|
94
106
|
end
|
107
|
+
# rubocop:enable Metrics/BlockLength
|
95
108
|
|
96
109
|
# Returns the combination of all documents in the collections that are
|
97
110
|
# specified
|
@@ -175,17 +188,9 @@ module Bridgetown
|
|
175
188
|
# template - The index.html Page that requires pagination.
|
176
189
|
# config - The configuration settings that should be used
|
177
190
|
#
|
178
|
-
def paginate(
|
179
|
-
template,
|
180
|
-
config,
|
181
|
-
site_title,
|
182
|
-
all_posts,
|
183
|
-
all_tags,
|
184
|
-
all_categories,
|
185
|
-
all_locales
|
186
|
-
)
|
191
|
+
def paginate(template, config, site_title, documents_payload)
|
187
192
|
# By default paginate on all posts in the site
|
188
|
-
using_posts =
|
193
|
+
using_posts = documents_payload[:posts]
|
189
194
|
|
190
195
|
# Now start filtering out any posts that the user doesn't want included
|
191
196
|
# in the pagination
|
@@ -194,26 +199,43 @@ module Bridgetown
|
|
194
199
|
config,
|
195
200
|
"category",
|
196
201
|
using_posts,
|
197
|
-
|
202
|
+
documents_payload[:categories]
|
198
203
|
)
|
199
204
|
_debug_print_filtering_info("Category", before, using_posts.size.to_i)
|
205
|
+
|
200
206
|
before = using_posts.size.to_i
|
201
207
|
using_posts = PaginationIndexer.read_config_value_and_filter_documents(
|
202
208
|
config,
|
203
209
|
"tag",
|
204
210
|
using_posts,
|
205
|
-
|
211
|
+
documents_payload[:tags]
|
206
212
|
)
|
207
213
|
_debug_print_filtering_info("Tag", before, using_posts.size.to_i)
|
214
|
+
|
208
215
|
before = using_posts.size.to_i
|
209
216
|
using_posts = PaginationIndexer.read_config_value_and_filter_documents(
|
210
217
|
config,
|
211
218
|
"locale",
|
212
219
|
using_posts,
|
213
|
-
|
220
|
+
documents_payload[:locales]
|
214
221
|
)
|
215
222
|
_debug_print_filtering_info("Locale", before, using_posts.size.to_i)
|
216
223
|
|
224
|
+
if config["where_query"]
|
225
|
+
before = using_posts.size.to_i
|
226
|
+
using_posts = PaginationIndexer.read_config_value_and_filter_documents(
|
227
|
+
config,
|
228
|
+
"where_query",
|
229
|
+
using_posts,
|
230
|
+
documents_payload[:where_matches]
|
231
|
+
)
|
232
|
+
_debug_print_filtering_info(
|
233
|
+
"Where Query (#{config["where_query"]})",
|
234
|
+
before,
|
235
|
+
using_posts.size.to_i
|
236
|
+
)
|
237
|
+
end
|
238
|
+
|
217
239
|
# Apply sorting to the posts if configured, any field for the post is
|
218
240
|
# available for sorting
|
219
241
|
if config["sort_field"]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bridgetown-paginate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bridgetown Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bridgetown-core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.9.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.9.0
|
27
27
|
description:
|
28
28
|
email: maintainers@bridgetownrb.com
|
29
29
|
executables: []
|