jekyll-algolia 1.0.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +51 -30
  3. data/README.md +69 -27
  4. data/lib/errors/invalid_credentials.txt +12 -0
  5. data/lib/errors/invalid_index_name.txt +9 -0
  6. data/lib/errors/missing_api_key.txt +15 -0
  7. data/lib/errors/missing_application_id.txt +11 -0
  8. data/lib/errors/missing_index_name.txt +18 -0
  9. data/lib/errors/no_records_found.txt +14 -0
  10. data/lib/errors/record_too_big.txt +27 -0
  11. data/lib/errors/record_too_big_api.txt +10 -0
  12. data/lib/errors/settings_manually_edited.txt +17 -0
  13. data/lib/errors/too_many_records.txt +14 -0
  14. data/lib/errors/unknown_application_id.txt +16 -0
  15. data/lib/errors/unknown_settings.txt +12 -0
  16. data/lib/jekyll-algolia.rb +45 -60
  17. data/lib/jekyll/algolia/configurator.rb +137 -44
  18. data/lib/jekyll/algolia/error_handler.rb +36 -48
  19. data/lib/jekyll/algolia/extractor.rb +16 -6
  20. data/lib/jekyll/algolia/file_browser.rb +161 -68
  21. data/lib/jekyll/algolia/hooks.rb +18 -6
  22. data/lib/jekyll/algolia/indexer.rb +283 -145
  23. data/lib/jekyll/algolia/logger.rb +39 -8
  24. data/lib/jekyll/algolia/overwrites/githubpages-configuration.rb +32 -0
  25. data/lib/jekyll/algolia/overwrites/jekyll-algolia-site.rb +151 -0
  26. data/lib/jekyll/algolia/overwrites/jekyll-document.rb +13 -0
  27. data/lib/jekyll/algolia/overwrites/jekyll-paginate-pager.rb +20 -0
  28. data/lib/jekyll/algolia/overwrites/jekyll-tags-link.rb +33 -0
  29. data/lib/jekyll/algolia/progress_bar.rb +27 -0
  30. data/lib/jekyll/algolia/shrinker.rb +112 -0
  31. data/lib/jekyll/algolia/utils.rb +118 -2
  32. data/lib/jekyll/algolia/version.rb +1 -1
  33. data/lib/jekyll/commands/algolia.rb +3 -14
  34. metadata +75 -31
  35. data/errors/invalid_credentials.txt +0 -10
  36. data/errors/invalid_credentials_for_tmp_index.txt +0 -17
  37. data/errors/invalid_index_name.txt +0 -11
  38. data/errors/missing_api_key.txt +0 -17
  39. data/errors/missing_application_id.txt +0 -12
  40. data/errors/missing_index_name.txt +0 -19
  41. data/errors/no_records_found.txt +0 -20
  42. data/errors/record_too_big.txt +0 -25
  43. data/errors/unknown_application_id.txt +0 -20
  44. data/errors/unknown_settings.txt +0 -15
@@ -6,6 +6,19 @@ module Jekyll
6
6
  module Algolia
7
7
  # Generic language-wide utils
8
8
  module Utils
9
+ # Public: Allow redefining an instance method on the fly with a new one
10
+ #
11
+ # instance - The instance to overwrite
12
+ # method - The method symbol to overwrite
13
+ # block - The new block to use for replacing (as a proc)
14
+ #
15
+ # Solution found on
16
+ # https://stackoverflow.com/questions/803020/redefining-a-single-ruby-method-on-a-single-instance-with-a-lambda/16631789
17
+ def self.monkey_patch(instance, method, block)
18
+ metaclass = class << instance; self; end
19
+ metaclass.send(:define_method, method, block)
20
+ end
21
+
9
22
  # Public: Convert a hash with string keys to a hash with symbol keys
10
23
  #
11
24
  # hash - The input hash, with string keys
@@ -13,22 +26,36 @@ module Jekyll
13
26
  Hash[hash.map { |key, value| [key.to_sym, value] }]
14
27
  end
15
28
 
29
+ # Public: Check if a variable is an instance of a specific class
30
+ #
31
+ # input - the variable to test
32
+ # classname - the string representation of the class
33
+ def self.instance_of?(input, classname)
34
+ input.instance_of? Object.const_get(classname)
35
+ rescue StandardError
36
+ # The class might not even exist
37
+ false
38
+ end
39
+
16
40
  # Public: Convert an HTML string to its content only
17
41
  #
18
42
  # html - String representation of the HTML node
19
43
  def self.html_to_text(html)
44
+ return nil if html.nil?
45
+
20
46
  text = Nokogiri::HTML(html).text
21
47
  text.tr("\n", ' ').squeeze(' ').strip
22
48
  end
23
49
 
24
- # Public: Remove all keys with a nil value or an empty array from a hash
50
+ # Public: Remove all keys with a nil value or an empty string from a hash
25
51
  #
26
52
  # hash - The input hash
27
53
  def self.compact_empty(hash)
28
54
  new_hash = {}
29
55
  hash.each do |key, value|
30
56
  next if value.nil?
31
- next if value.respond_to?(:empty?) && value.empty?
57
+ next if value.is_a?(String) && value.empty?
58
+
32
59
  new_hash[key] = value
33
60
  end
34
61
  new_hash
@@ -59,10 +86,99 @@ module Jekyll
59
86
  # It is basically a wrapper around [].find, handling more edge-cases
60
87
  def self.find_by_key(items, key, value)
61
88
  return nil if items.nil?
89
+
62
90
  items.find do |item|
63
91
  item[key] == value
64
92
  end
65
93
  end
94
+
95
+ # Public: Convert an object into an object that can easily be converted to
96
+ # JSON, to be stored as a record
97
+ #
98
+ # item - The object to convert
99
+ #
100
+ # It will keep any string, number, boolean,boolean,array or nested object,
101
+ # but will try to stringify other objects, excluding the one that contain
102
+ # a unique identifier once serialized.
103
+ def self.jsonify(item)
104
+ simple_types = [
105
+ NilClass,
106
+ TrueClass, FalseClass,
107
+ Integer, Float,
108
+ String
109
+ ]
110
+ # Integer arrived in Ruby 2.4. Before that it was Fixnum and Bignum
111
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.4.0')
112
+ # rubocop:disable Lint/UnifiedInteger
113
+ simple_types += [Fixnum, Bignum]
114
+ # rubocop:enable Lint/UnifiedInteger
115
+ end
116
+ return item if simple_types.member?(item.class)
117
+
118
+ # Recursive types
119
+ return item.map { |value| jsonify(value) } if item.is_a?(Array)
120
+ if item.is_a?(Hash)
121
+ return item.map { |key, value| [key, jsonify(value)] }.to_h
122
+ end
123
+
124
+ # Can't be stringified, discard it
125
+ return nil unless item.respond_to?(:to_s)
126
+
127
+ # Discard also if is a serialized version with unique identifier
128
+ stringified = item.to_s
129
+ return nil if match?(stringified, /#<[^ ].*@[0-9]* .*>/)
130
+
131
+ stringified
132
+ end
133
+
134
+ # Public: Get a hash representing the difference between two hashes
135
+ #
136
+ # It only checks that all keys of alpha are also in beta, with the same
137
+ # value. If not, it remember what was the value of beta and return it in
138
+ # the output
139
+ def self.diff_keys(alpha, beta)
140
+ diff = {}
141
+ alpha.each do |key, value|
142
+ diff[key] = beta[key] if beta[key] != value
143
+ end
144
+
145
+ return nil if diff.empty?
146
+
147
+ diff
148
+ end
149
+
150
+ # Public: Split a long text into lines of specific length
151
+ #
152
+ # It takes care to not cut words
153
+ def self.split_lines(input, max_length)
154
+ # Force splitting on actual new lines first
155
+ if input.include?("\n")
156
+ output = []
157
+ input.split("\n").each do |line|
158
+ output += split_lines(line, max_length)
159
+ end
160
+ return output
161
+ end
162
+
163
+ output = []
164
+ words = input.split(' ')
165
+ current_line = words.shift || ''
166
+ test_line = '' # must be defined outside of the loop
167
+
168
+ words.each do |word|
169
+ test_line = "#{current_line} #{word}"
170
+ if test_line.length > max_length
171
+ output << current_line
172
+ current_line = word
173
+ next
174
+ end
175
+ current_line = test_line
176
+ end
177
+ output << current_line
178
+
179
+ # Making sure all lines are the same length
180
+ output.map { |line| line.ljust(max_length, ' ') }
181
+ end
66
182
  end
67
183
  end
68
184
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Algolia
5
- VERSION = '1.0.0'
5
+ VERSION = '1.6.0'
6
6
  end
7
7
  end
@@ -14,20 +14,6 @@ module Jekyll
14
14
  '--config CONFIG_FILE[,CONFIG_FILE2,...]',
15
15
  Array,
16
16
  'Custom configuration file'
17
- command.option 'future',
18
- '--future',
19
- 'Index posts with a future date'
20
- command.option 'limit_posts',
21
- '--limit_posts MAX_POSTS',
22
- Integer,
23
- 'Limits the number of posts to parse and index'
24
- command.option 'show_drafts',
25
- '-D',
26
- '--drafts',
27
- 'Index posts in the _drafts folder'
28
- command.option 'unpublished',
29
- '--unpublished',
30
- 'Index posts that were marked as unpublished'
31
17
  command.option 'dry_run',
32
18
  '--dry-run',
33
19
  '-n',
@@ -35,6 +21,9 @@ module Jekyll
35
21
  command.option 'verbose',
36
22
  '--verbose',
37
23
  'Display more information on what is indexed'
24
+ command.option 'force_settings',
25
+ '--force-settings',
26
+ 'Force updating of the index settings'
38
27
 
39
28
  command.action do |_, options|
40
29
  configuration = configuration_from_options(options)
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-algolia
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Carry
8
+ - Sylvain Utard
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2017-12-21 00:00:00.000000000 Z
12
+ date: 2019-10-21 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: algolia_html_extractor
@@ -16,28 +17,28 @@ dependencies:
16
17
  requirements:
17
18
  - - "~>"
18
19
  - !ruby/object:Gem::Version
19
- version: '2.2'
20
+ version: '2.6'
20
21
  type: :runtime
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
25
  - - "~>"
25
26
  - !ruby/object:Gem::Version
26
- version: '2.2'
27
+ version: '2.6'
27
28
  - !ruby/object:Gem::Dependency
28
29
  name: algoliasearch
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
32
  - - "~>"
32
33
  - !ruby/object:Gem::Version
33
- version: '1.18'
34
+ version: '1.26'
34
35
  type: :runtime
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
39
  - - "~>"
39
40
  - !ruby/object:Gem::Version
40
- version: '1.18'
41
+ version: '1.26'
41
42
  - !ruby/object:Gem::Dependency
42
43
  name: filesize
43
44
  requirement: !ruby/object:Gem::Requirement
@@ -56,58 +57,64 @@ dependencies:
56
57
  name: jekyll
57
58
  requirement: !ruby/object:Gem::Requirement
58
59
  requirements:
59
- - - "~>"
60
+ - - ">="
60
61
  - !ruby/object:Gem::Version
61
- version: '3.0'
62
+ version: '3.6'
63
+ - - "<"
64
+ - !ruby/object:Gem::Version
65
+ version: '5.0'
62
66
  type: :runtime
63
67
  prerelease: false
64
68
  version_requirements: !ruby/object:Gem::Requirement
65
69
  requirements:
66
- - - "~>"
70
+ - - ">="
67
71
  - !ruby/object:Gem::Version
68
- version: '3.0'
72
+ version: '3.6'
73
+ - - "<"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
69
76
  - !ruby/object:Gem::Dependency
70
- name: jekyll-paginate
77
+ name: json
71
78
  requirement: !ruby/object:Gem::Requirement
72
79
  requirements:
73
80
  - - "~>"
74
81
  - !ruby/object:Gem::Version
75
- version: '1.1'
82
+ version: '2.0'
76
83
  type: :runtime
77
84
  prerelease: false
78
85
  version_requirements: !ruby/object:Gem::Requirement
79
86
  requirements:
80
87
  - - "~>"
81
88
  - !ruby/object:Gem::Version
82
- version: '1.1'
89
+ version: '2.0'
83
90
  - !ruby/object:Gem::Dependency
84
- name: json
91
+ name: nokogiri
85
92
  requirement: !ruby/object:Gem::Requirement
86
93
  requirements:
87
94
  - - "~>"
88
95
  - !ruby/object:Gem::Version
89
- version: '2.0'
96
+ version: '1.6'
90
97
  type: :runtime
91
98
  prerelease: false
92
99
  version_requirements: !ruby/object:Gem::Requirement
93
100
  requirements:
94
101
  - - "~>"
95
102
  - !ruby/object:Gem::Version
96
- version: '2.0'
103
+ version: '1.6'
97
104
  - !ruby/object:Gem::Dependency
98
- name: nokogiri
105
+ name: progressbar
99
106
  requirement: !ruby/object:Gem::Requirement
100
107
  requirements:
101
108
  - - "~>"
102
109
  - !ruby/object:Gem::Version
103
- version: '1.6'
110
+ version: '1.9'
104
111
  type: :runtime
105
112
  prerelease: false
106
113
  version_requirements: !ruby/object:Gem::Requirement
107
114
  requirements:
108
115
  - - "~>"
109
116
  - !ruby/object:Gem::Version
110
- version: '1.6'
117
+ version: '1.9'
111
118
  - !ruby/object:Gem::Dependency
112
119
  name: verbal_expressions
113
120
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +129,20 @@ dependencies:
122
129
  - - "~>"
123
130
  - !ruby/object:Gem::Version
124
131
  version: 0.1.5
132
+ - !ruby/object:Gem::Dependency
133
+ name: awesome_print
134
+ requirement: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.8'
139
+ type: :development
140
+ prerelease: false
141
+ version_requirements: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '1.8'
125
146
  - !ruby/object:Gem::Dependency
126
147
  name: coveralls
127
148
  requirement: !ruby/object:Gem::Requirement
@@ -164,6 +185,20 @@ dependencies:
164
185
  - - "~>"
165
186
  - !ruby/object:Gem::Version
166
187
  version: '4.3'
188
+ - !ruby/object:Gem::Dependency
189
+ name: guard
190
+ requirement: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '2.14'
195
+ type: :development
196
+ prerelease: false
197
+ version_requirements: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: '2.14'
167
202
  - !ruby/object:Gem::Dependency
168
203
  name: guard-rspec
169
204
  requirement: !ruby/object:Gem::Requirement
@@ -249,23 +284,25 @@ dependencies:
249
284
  - !ruby/object:Gem::Version
250
285
  version: '0.10'
251
286
  description: Index all your content into Algolia by running `jekyll algolia`
252
- email: tim@pixelastic.com
287
+ email: support@algolia.com
253
288
  executables: []
254
289
  extensions: []
255
290
  extra_rdoc_files: []
256
291
  files:
257
292
  - CONTRIBUTING.md
258
293
  - README.md
259
- - errors/invalid_credentials.txt
260
- - errors/invalid_credentials_for_tmp_index.txt
261
- - errors/invalid_index_name.txt
262
- - errors/missing_api_key.txt
263
- - errors/missing_application_id.txt
264
- - errors/missing_index_name.txt
265
- - errors/no_records_found.txt
266
- - errors/record_too_big.txt
267
- - errors/unknown_application_id.txt
268
- - errors/unknown_settings.txt
294
+ - lib/errors/invalid_credentials.txt
295
+ - lib/errors/invalid_index_name.txt
296
+ - lib/errors/missing_api_key.txt
297
+ - lib/errors/missing_application_id.txt
298
+ - lib/errors/missing_index_name.txt
299
+ - lib/errors/no_records_found.txt
300
+ - lib/errors/record_too_big.txt
301
+ - lib/errors/record_too_big_api.txt
302
+ - lib/errors/settings_manually_edited.txt
303
+ - lib/errors/too_many_records.txt
304
+ - lib/errors/unknown_application_id.txt
305
+ - lib/errors/unknown_settings.txt
269
306
  - lib/jekyll-algolia.rb
270
307
  - lib/jekyll/algolia/configurator.rb
271
308
  - lib/jekyll/algolia/error_handler.rb
@@ -274,6 +311,13 @@ files:
274
311
  - lib/jekyll/algolia/hooks.rb
275
312
  - lib/jekyll/algolia/indexer.rb
276
313
  - lib/jekyll/algolia/logger.rb
314
+ - lib/jekyll/algolia/overwrites/githubpages-configuration.rb
315
+ - lib/jekyll/algolia/overwrites/jekyll-algolia-site.rb
316
+ - lib/jekyll/algolia/overwrites/jekyll-document.rb
317
+ - lib/jekyll/algolia/overwrites/jekyll-paginate-pager.rb
318
+ - lib/jekyll/algolia/overwrites/jekyll-tags-link.rb
319
+ - lib/jekyll/algolia/progress_bar.rb
320
+ - lib/jekyll/algolia/shrinker.rb
277
321
  - lib/jekyll/algolia/utils.rb
278
322
  - lib/jekyll/algolia/version.rb
279
323
  - lib/jekyll/commands/algolia.rb
@@ -297,7 +341,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
297
341
  version: '0'
298
342
  requirements: []
299
343
  rubyforge_project:
300
- rubygems_version: 2.6.13
344
+ rubygems_version: 2.5.2.3
301
345
  signing_key:
302
346
  specification_version: 4
303
347
  summary: Index your Jekyll content into Algolia
@@ -1,10 +0,0 @@
1
- E: [✗ Error] Invalid credentials
2
- E:
3
- E: The jekyll-algolia plugin could not connect to your application ID using the
4
- E: API key your provided.
5
- W:
6
- W: Make sure your API key has access to your {application_id} application.
7
- I:
8
- I: You can find your API key in your Algolia dashboard here:
9
- I: https://www.algolia.com/licensing
10
- I:
@@ -1,17 +0,0 @@
1
- E: [✗ Error] Invalid credentials for temporary index
2
- E:
3
- E: The jekyll-algolia plugin could not access your index with the API key you
4
- E: provided.
5
- W:
6
- W: When using the `atomic` indexing mode, we will push all your content to a
7
- W: temporary index, then overwrite the actual index with it. The API key you
8
- W: defined should have access rights on both.
9
- I:
10
- I: Make sure your API key has access:
11
- I: - {index_name}
12
- I: - {index_name_tmp}
13
- I:
14
- I: You can configure API keys from your dashboard:
15
- I: https://www.algolia.com/apps/{application_id}/api-keys/restricted
16
- I:
17
- I: