jekyll-algolia 1.4.0 → 1.4.1
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/README.md +20 -16
- data/lib/errors/record_too_big.txt +9 -7
- data/lib/errors/record_too_big_api.txt +10 -0
- data/lib/jekyll/algolia/configurator.rb +1 -0
- data/lib/jekyll/algolia/error_handler.rb +11 -48
- data/lib/jekyll/algolia/overwrites/githubpages-configuration.rb +12 -4
- data/lib/jekyll/algolia/overwrites/jekyll-algolia-site.rb +5 -3
- data/lib/jekyll/algolia/shrinker.rb +63 -4
- data/lib/jekyll/algolia/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 481b7a00fb77312b22d28dd2f36c1451716016ca
|
4
|
+
data.tar.gz: c9d0db5c134418357f510fd30085031b28a6ffca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cb7407675f31cdd3f11a4584df1f110934fab993fd60d98fe591dbfa82fd56a2773d3d7721dcc7a488c0c1977e67429226bdd500520a85c995f1c60936bfb36
|
7
|
+
data.tar.gz: 061740db0b6b2061eb0b16116f1b5c9a0425b191096030b5d99967cccd1b4fa611c78c5e9e4fb903d6ed067b558c623fdacf75dc0426694d3b8bbb15357bb1f6
|
data/README.md
CHANGED
@@ -45,12 +45,12 @@ Once this is done, download all dependencies with `bundle install`.
|
|
45
45
|
You need to provide certain Algolia credentials for this plugin to *index* your
|
46
46
|
site.
|
47
47
|
|
48
|
-
*If you don't yet have an Algolia account, you
|
49
|
-
here][8].
|
50
|
-
|
48
|
+
*If you don't yet have an Algolia account, we suggest that you open a free
|
49
|
+
[Community plan here][8]. You can find more information about the Algolia plans
|
50
|
+
[in our FAQ][10].*
|
51
51
|
|
52
|
-
Once
|
53
|
-
your `_config.yml` file like this:
|
52
|
+
Once signed in, you should get your application ID from [your dashboard][9] and
|
53
|
+
define it inside your `_config.yml` file like this:
|
54
54
|
|
55
55
|
```yaml
|
56
56
|
# _config.yml
|
@@ -72,18 +72,21 @@ Note that `ALGOLIA_API_KEY` should be set to your admin API key.
|
|
72
72
|
|
73
73
|
## More about the Community plan
|
74
74
|
|
75
|
-
The Algolia [Community plan][
|
76
|
-
100k add/edit/delete operations per month (search operations are free). The
|
77
|
-
is entirely free, with no time limit.
|
75
|
+
The Algolia [Community plan][11] lets you host up to 10k records and perform up
|
76
|
+
to 100k add/edit/delete operations per month (search operations are free). The
|
77
|
+
plan is entirely free, with no time limit.
|
78
78
|
|
79
79
|
What we ask in exchange is that you display a "Search by Algolia" logo next to
|
80
|
-
your search results. Our [InstantSearch libraries][
|
80
|
+
your search results. Our [InstantSearch libraries][12] have a simple boolean
|
81
81
|
option to toggle that on an off. If you want more flexibility, you can find
|
82
|
-
all versions of our logo [here][
|
82
|
+
all versions of our logo [here][13].
|
83
|
+
|
84
|
+
If you need more information about the other Algolia plans, you can [check our
|
85
|
+
FAQ][10].
|
83
86
|
|
84
87
|
# Thanks
|
85
88
|
|
86
|
-
Thanks to [Anatoliy Yastreb][
|
89
|
+
Thanks to [Anatoliy Yastreb][14] for a [great tutorial][15] on creating Jekyll
|
87
90
|
plugins.
|
88
91
|
|
89
92
|
|
@@ -96,8 +99,9 @@ plugins.
|
|
96
99
|
[7]: https://img.shields.io/badge/dynamic/json.svg?label=coverage%3Adevelop&colorB=&prefix=&suffix=%25&query=$.coverage_change&uri=https%3A%2F%2Fcoveralls.io%2Fgithub%2Falgolia%2Fjekyll-algolia.json%3Fbranch%3Ddevelop
|
97
100
|
[8]: #more-about-the-community-plan
|
98
101
|
[9]: https://www.algolia.com/api-keys
|
99
|
-
[10]: https://
|
100
|
-
[11]: https://
|
101
|
-
[12]: https://
|
102
|
-
[13]: https://
|
103
|
-
[14]: https://
|
102
|
+
[10]: https://community.algolia.com/jekyll-algolia/faq.html#how-many-records-will-the-plugin-need
|
103
|
+
[11]: https://www.algolia.com/users/sign_up/hacker
|
104
|
+
[12]: https://community.algolia.com/instantsearch.js/
|
105
|
+
[13]: https://www.algolia.com/press#resources
|
106
|
+
[14]: https://github.com/ayastreb/
|
107
|
+
[15]: https://ayastreb.me/writing-a-jekyll-plugin/
|
@@ -1,14 +1,10 @@
|
|
1
1
|
E:[✗ Error] Record is too big
|
2
2
|
E:
|
3
|
-
E:The jekyll-algolia plugin
|
3
|
+
E:The jekyll-algolia plugin detected that one of your records exceeds the {max_record_size} record size limit.
|
4
4
|
W:
|
5
|
-
W:The plugin will create one record for each element matching your `nodes_to_index` value (currently set to "{nodes_to_index}").
|
6
|
-
W:Each record should not weight more than {size_limit}.
|
7
|
-
W:One of your records weights {size} and has been rejected.
|
8
|
-
W:
|
9
|
-
W:objectID: {object_id}
|
10
5
|
W:title: {object_title}
|
11
6
|
W:url: {object_url}
|
7
|
+
W:size: {record_size}
|
12
8
|
W:
|
13
9
|
W:Most probable keys causing the issue:
|
14
10
|
W: {probable_wrong_keys}
|
@@ -18,5 +14,11 @@ W: {record_log_path}
|
|
18
14
|
W:
|
19
15
|
I:This issue can be caused by malformed HTML preventing the parser to correctly grab the content of the nodes. Double check that the page actually renders correctly with a regular `jekyll build`.
|
20
16
|
I:
|
21
|
-
I:If you
|
17
|
+
I:If you think this is an error and your current Algolia plan should allow you to push records bigger than {max_record_size}, you can change the `max_record_size` config option to increase the limit. Paid plans have a limit set to 20Kb, while free Community plans have it set to 10Kb.
|
18
|
+
I:
|
19
|
+
I:The following documentation might help you:
|
20
|
+
I: - https://community.algolia.com/jekyll-algolia/options.html#nodes-to-index
|
21
|
+
I: - https://community.algolia.com/jekyll-algolia/options.html#max-record-size
|
22
|
+
I:
|
23
|
+
I:If you're still having trouble solving this issue, feel free to file a bug on GitHub, ideally with a link to a repository where we can reproduce the issue.
|
22
24
|
I: https://github.com/algolia/jekyll-algolia/issues
|
@@ -0,0 +1,10 @@
|
|
1
|
+
E:[✗ Error] Record is too big
|
2
|
+
E:
|
3
|
+
E:The API rejected one of your records because it is too big ({record_size}).
|
4
|
+
W:
|
5
|
+
W:Make sure the value of `max_record_size` (currently set to "{max_record_size}") matches the maximum size allowed by your current Algolia plan.
|
6
|
+
W:
|
7
|
+
I:Free Community plans can push records up to 10Kb (`max_record_size: 10000`, this is the default value), while paid plans can go up to 20Kb (`max_record_size: 20000`).
|
8
|
+
I:
|
9
|
+
I:If you're still having trouble solving this issue, feel free to file a bug on GitHub, ideally with a link to a repository where we can reproduce the issue.
|
10
|
+
I: https://github.com/algolia/jekyll-algolia/issues
|
@@ -47,7 +47,7 @@ module Jekyll
|
|
47
47
|
known_errors = %w[
|
48
48
|
unknown_application_id
|
49
49
|
invalid_credentials
|
50
|
-
|
50
|
+
record_too_big_api
|
51
51
|
too_many_records
|
52
52
|
unknown_setting
|
53
53
|
invalid_index_name
|
@@ -135,24 +135,6 @@ module Jekyll
|
|
135
135
|
hash
|
136
136
|
end
|
137
137
|
|
138
|
-
# Public: Returns a string explaining which attributes are the largest in
|
139
|
-
# the record
|
140
|
-
#
|
141
|
-
# record - The record hash to analyze
|
142
|
-
#
|
143
|
-
# This will be used on the `record_too_big` error, to guide users in
|
144
|
-
# finding which record is causing trouble
|
145
|
-
def self.readable_largest_record_keys(record)
|
146
|
-
keys = Hash[record.map { |key, value| [key, value.to_s.length] }]
|
147
|
-
largest_keys = keys.sort_by { |_, value| value }.reverse[0..2]
|
148
|
-
output = []
|
149
|
-
largest_keys.each do |key, size|
|
150
|
-
size = Filesize.from("#{size} B").to_s('Kb')
|
151
|
-
output << "#{key} (#{size})"
|
152
|
-
end
|
153
|
-
output.join(', ')
|
154
|
-
end
|
155
|
-
|
156
138
|
# Public: Check if the application id is available
|
157
139
|
#
|
158
140
|
# _context - Not used
|
@@ -197,43 +179,24 @@ module Jekyll
|
|
197
179
|
#
|
198
180
|
# context[:records] - list of records sent in the batch
|
199
181
|
#
|
200
|
-
#
|
201
|
-
#
|
202
|
-
#
|
203
|
-
|
182
|
+
# One of the sent record is too big and has been rejected by the API. This
|
183
|
+
# should not happen as we proactively check for record size before pushing
|
184
|
+
# them. If it still happens it means that the value set in max_record_size
|
185
|
+
# is not matching the value in the plan.
|
186
|
+
def self.record_too_big_api?(error, _contex = {})
|
204
187
|
details = error_hash(error.message)
|
205
188
|
return false if details == false
|
206
189
|
|
207
190
|
message = details['message']
|
208
191
|
return false if message !~ /^Record .* is too big .*/
|
209
192
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
object_id = details['objectID']
|
214
|
-
|
215
|
-
# Finding the record in all the operations
|
216
|
-
operation = context[:operations].find do |o|
|
217
|
-
o[:action] == 'addObject' && o[:body][:objectID] == object_id
|
218
|
-
end
|
219
|
-
record = operation[:body]
|
220
|
-
probable_wrong_keys = readable_largest_record_keys(record)
|
221
|
-
|
222
|
-
# Writing the full record to disk for inspection
|
223
|
-
record_log_path = Logger.write_to_file(
|
224
|
-
"jekyll-algolia-record-too-big-#{object_id}.log",
|
225
|
-
JSON.pretty_generate(record)
|
226
|
-
)
|
193
|
+
record_size, = /.*size=(.*) bytes.*/.match(message).captures
|
194
|
+
record_size_readable = Filesize.from("#{record_size}B").to_s('Kb')
|
195
|
+
max_record_size = Configurator.algolia('max_record_size')
|
227
196
|
|
228
197
|
{
|
229
|
-
'
|
230
|
-
'
|
231
|
-
'object_url' => record[:url],
|
232
|
-
'probable_wrong_keys' => probable_wrong_keys,
|
233
|
-
'record_log_path' => record_log_path,
|
234
|
-
'nodes_to_index' => Configurator.algolia('nodes_to_index'),
|
235
|
-
'size' => size,
|
236
|
-
'size_limit' => '10 Kb'
|
198
|
+
'record_size' => record_size_readable,
|
199
|
+
'max_record_size' => max_record_size
|
237
200
|
}
|
238
201
|
end
|
239
202
|
|
@@ -10,15 +10,23 @@ module GitHubPages
|
|
10
10
|
# github-pages gem installed at the same time, those hooks will never be
|
11
11
|
# executed.
|
12
12
|
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
13
|
+
# The GitHub Pages gem prevent access to custom plugins by doing two things:
|
14
|
+
# - forcing safe mode
|
15
|
+
# - loading custom plugins from a random dir
|
16
|
+
#
|
17
|
+
# We cancel those by disabling safe mode and forcing back plugins to be read
|
18
|
+
# from ./_plugins.
|
16
19
|
#
|
17
20
|
# This file will only be loaded when running `jekyll algolia`, so it won't
|
18
21
|
# interfere with the regular usage of `jekyll build`
|
19
22
|
class Configuration
|
20
23
|
class << self
|
21
|
-
def set(site)
|
24
|
+
def set!(site)
|
25
|
+
config = effective_config(site.config)
|
26
|
+
config['safe'] = false
|
27
|
+
config['plugins_dir'] = '_plugins'
|
28
|
+
site.config = config
|
29
|
+
end
|
22
30
|
end
|
23
31
|
end
|
24
32
|
end
|
@@ -130,13 +130,15 @@ module Jekyll
|
|
130
130
|
# Applying the user hook on the whole list of records
|
131
131
|
records = Hooks.apply_all(records, self)
|
132
132
|
|
133
|
-
# Shrinking records to
|
133
|
+
# Shrinking records to force them to fit under the max record size
|
134
|
+
# limit, or displaying an error message if not possible
|
135
|
+
max_record_size = Configurator.algolia('max_record_size')
|
134
136
|
# We take into account the objectID that will be added in the form of:
|
135
137
|
# "objectID": "16cd998991cc40d92402b0b4e6c55e8a"
|
136
138
|
object_id_attribute_length = 46
|
137
|
-
|
139
|
+
max_record_size -= object_id_attribute_length
|
138
140
|
records.map! do |record|
|
139
|
-
Shrinker.fit_to_size(record,
|
141
|
+
Shrinker.fit_to_size(record, max_record_size)
|
140
142
|
end
|
141
143
|
|
142
144
|
# Adding a unique objectID to each record
|
@@ -25,7 +25,7 @@ module Jekyll
|
|
25
25
|
return raw_record if size(raw_record) <= max_size
|
26
26
|
|
27
27
|
# No excerpt, we can't shrink it
|
28
|
-
return raw_record unless raw_record.key?(:excerpt_html)
|
28
|
+
return stop_with_error(raw_record) unless raw_record.key?(:excerpt_html)
|
29
29
|
|
30
30
|
record = raw_record.clone
|
31
31
|
|
@@ -41,10 +41,69 @@ module Jekyll
|
|
41
41
|
return record if size(record) <= max_size
|
42
42
|
|
43
43
|
# We remove the excerpts completely
|
44
|
-
record
|
45
|
-
record
|
44
|
+
record.delete(:excerpt_text)
|
45
|
+
record.delete(:excerpt_html)
|
46
|
+
return record if size(record) <= max_size
|
47
|
+
|
48
|
+
# Still too big, we fail
|
49
|
+
stop_with_error(record)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Public: Stop the current indexing process and display details about the
|
53
|
+
# record that is too big to be pushed
|
54
|
+
#
|
55
|
+
# - record: The record causing the error
|
56
|
+
#
|
57
|
+
# This will display an error message and log the wrong record in a file in
|
58
|
+
# the source directory
|
59
|
+
def self.stop_with_error(record)
|
60
|
+
record_size = size(record)
|
61
|
+
record_size_readable = Filesize.from("#{record_size}B").to_s('Kb')
|
62
|
+
max_record_size = Configurator.algolia('max_record_size')
|
63
|
+
max_record_size_readable = Filesize
|
64
|
+
.from("#{max_record_size}B").to_s('Kb')
|
65
|
+
|
66
|
+
probable_wrong_keys = readable_largest_record_keys(record)
|
67
|
+
|
68
|
+
# Writing the full record to disk for inspection
|
69
|
+
record_log_path = Logger.write_to_file(
|
70
|
+
'jekyll-algolia-record-too-big.log',
|
71
|
+
JSON.pretty_generate(record)
|
72
|
+
)
|
73
|
+
|
74
|
+
details = {
|
75
|
+
'object_title' => record[:title],
|
76
|
+
'object_url' => record[:url],
|
77
|
+
'probable_wrong_keys' => probable_wrong_keys,
|
78
|
+
'record_log_path' => record_log_path,
|
79
|
+
'nodes_to_index' => Configurator.algolia('nodes_to_index'),
|
80
|
+
'record_size' => record_size_readable,
|
81
|
+
'max_record_size' => max_record_size_readable
|
82
|
+
}
|
83
|
+
|
84
|
+
Logger.known_message('record_too_big', details)
|
85
|
+
|
86
|
+
stop_process
|
87
|
+
end
|
88
|
+
|
89
|
+
# Public: Returns a string explaining which attributes are the largest in
|
90
|
+
# the record
|
91
|
+
#
|
92
|
+
# record - The record hash to analyze
|
93
|
+
def self.readable_largest_record_keys(record)
|
94
|
+
keys = Hash[record.map { |key, value| [key, value.to_s.length] }]
|
95
|
+
largest_keys = keys.sort_by { |_, value| value }.reverse[0..2]
|
96
|
+
output = []
|
97
|
+
largest_keys.each do |key, size|
|
98
|
+
size = Filesize.from("#{size} B").to_s('Kb')
|
99
|
+
output << "#{key} (#{size})"
|
100
|
+
end
|
101
|
+
output.join(', ')
|
102
|
+
end
|
46
103
|
|
47
|
-
|
104
|
+
# Public: Stop the current process
|
105
|
+
def self.stop_process
|
106
|
+
exit 1
|
48
107
|
end
|
49
108
|
end
|
50
109
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-algolia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Carry
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: algolia_html_extractor
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.6
|
19
|
+
version: '2.6'
|
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: 2.6
|
26
|
+
version: '2.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: algoliasearch
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -291,6 +291,7 @@ files:
|
|
291
291
|
- lib/errors/missing_index_name.txt
|
292
292
|
- lib/errors/no_records_found.txt
|
293
293
|
- lib/errors/record_too_big.txt
|
294
|
+
- lib/errors/record_too_big_api.txt
|
294
295
|
- lib/errors/settings_manually_edited.txt
|
295
296
|
- lib/errors/too_many_records.txt
|
296
297
|
- lib/errors/unknown_application_id.txt
|