jekyll-algolia 1.3.4 → 1.4.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: 6fa7433c628b7f2f1f4e343be4030d2852579797
4
- data.tar.gz: e15c05d2729c840cc1d84e0823dae386ef58ea4d
3
+ metadata.gz: df27608a53e92a6a6045233960ebed4d0428d724
4
+ data.tar.gz: 7aa5442e7b35440a88c70a71336f7055bd7739a3
5
5
  SHA512:
6
- metadata.gz: d32bc900f03aa56a30865366b3c6496e24ac2c8d579fcdfa03f543ff529809ba75bbdcad0212b9d2b9bf25bcf4a7c7b2b8c38daac2e89d94c13e05eeeec596cc
7
- data.tar.gz: 27f778ae3a134833e842a82cb2781771edea33d0968f89e6af9439a3228a2318a114d5e1ac7626ca5670164b20d0d511628bb212a260bdc8988f00b241c816c7
6
+ metadata.gz: cac19bf56a3777f5c6754e9b4309b22fe751c7076d54de4a91bd67e067c8a84f566542ad6b93b086a650cd844fa684f5fe9101605045428ded68c64a56370a80
7
+ data.tar.gz: 90b7b874c0a82d2b9e2d6015795c18ef9656ea41ab9f13b8c43de7309407bc023e9ee4a167343f4ea0f735303c192d38a444e2e6f32bb2e3ed77abda96451923
data/README.md CHANGED
@@ -65,7 +65,7 @@ Once your application ID is setup, you can run the indexing by running the
65
65
  following command:
66
66
 
67
67
  ```shell
68
- ALGOLIA_API_KEY='{your_admin_api_key}' bundle exec jekyll algolia
68
+ ALGOLIA_API_KEY='your_admin_api_key' bundle exec jekyll algolia
69
69
  ```
70
70
 
71
71
  Note that `ALGOLIA_API_KEY` should be set to your admin API key.
@@ -5,7 +5,7 @@ W:
5
5
  W:Please, define your API key either by:
6
6
  W:
7
7
  W:1/ Defining an ENV variable when calling `jekyll algolia`
8
- W:   $ ALGOLIA_API_KEY='{your_api_key}' jekyll algolia
8
+ W:   $ ALGOLIA_API_KEY='your_api_key' jekyll algolia
9
9
  W:
10
10
  W:2/ Save your API key in a named `_algolia_api_key` in your source directory.
11
11
  W:   If you do this, we strongly recommend you to NOT track this file in your versionning system.
@@ -5,7 +5,7 @@ W:
5
5
  W:Please, define it in your Jekyll _config.yml file like this:
6
6
  W:
7
7
  W:  algolia:
8
- W:   index_name: {your_index_name}
8
+ W:   index_name: your_index_name
9
9
  W:
10
10
  W:Alternatively, you can also define it as an ENV variable, like this:
11
11
  W:
@@ -13,5 +13,5 @@ W:algolia:
13
13
  W:  settings:
14
14
  {settings}
15
15
  I:
16
- I:If you'd like to revert to the default settings, the easiest way delete the indices and run `jekyll algolia` again.
16
+ I:If you'd like to revert to the default settings, the easiest way is to delete the {index_name} index from your dashboard and run `jekyll algolia` again.
17
17
  I:
@@ -12,5 +12,5 @@ I:
12
12
  I:Then, define it in your Jekyll _config.yml file like this:
13
13
  I:
14
14
  I:  algolia:
15
- I:    application_id: {your_application_id}
15
+ I:    application_id: your_application_id
16
16
  I:
@@ -15,6 +15,7 @@ module Jekyll
15
15
  require 'jekyll/algolia/indexer'
16
16
  require 'jekyll/algolia/logger'
17
17
  require 'jekyll/algolia/progress_bar'
18
+ require 'jekyll/algolia/shrinker'
18
19
  require 'jekyll/algolia/utils'
19
20
  require 'jekyll/algolia/version'
20
21
 
@@ -57,7 +57,8 @@ module Jekyll
57
57
  AlgoliaHTMLExtractor.run(
58
58
  content,
59
59
  options: {
60
- css_selector: Configurator.algolia('nodes_to_index')
60
+ css_selector: Configurator.algolia('nodes_to_index'),
61
+ tags_to_exclude: 'script,style,iframe'
61
62
  }
62
63
  )
63
64
  end
@@ -114,7 +114,7 @@ module Jekyll
114
114
  list.sort
115
115
  end
116
116
 
117
- # Public: Get an array of all the object ids, stored in the dedicated
117
+ # Public: Get an array of all the object ids, stored in a dedicated
118
118
  # index
119
119
  #
120
120
  # Note: This will be very fast. Each record contain 100 object id, so it
@@ -142,9 +142,13 @@ module Jekyll
142
142
  def self.remote_object_ids
143
143
  Logger.log('I:Getting list of existing records')
144
144
 
145
+ # Main index empty, the list is empty no matter what (we don't use the
146
+ # dedicated index in that case)
147
+ return [] if record_count(index).zero?
148
+
145
149
  # Fast version, using the dedicated index
146
- has_dedicated_index = index_exist?(index_object_ids)
147
- return remote_object_ids_from_dedicated_index if has_dedicated_index
150
+ has_object_id_index = index_exist?(index_object_ids)
151
+ return remote_object_ids_from_dedicated_index if has_object_id_index
148
152
 
149
153
  # Slow version, browsing the full index
150
154
  remote_object_ids_from_main_index
@@ -175,10 +179,10 @@ module Jekyll
175
179
 
176
180
  # What changes should we do to the indexes?
177
181
  has_records_to_update = !ids_to_delete.empty? || !ids_to_add.empty?
178
- has_dedicated_index = index_exist?(index_object_ids)
182
+ has_object_id_index = index_exist?(index_object_ids)
179
183
 
180
184
  # Stop if nothing to change
181
- if !has_records_to_update && has_dedicated_index
185
+ if !has_records_to_update && has_object_id_index
182
186
  Logger.log('I:Content is already up to date.')
183
187
  return
184
188
  end
@@ -212,9 +216,9 @@ module Jekyll
212
216
 
213
217
  # We update the dedicated index everytime we update records, but we also
214
218
  # create it if it does not exist
215
- should_update_dedicated_index = has_records_to_update ||
216
- !has_dedicated_index
217
- if should_update_dedicated_index
219
+ should_update_object_id_index = has_records_to_update ||
220
+ !has_object_id_index
221
+ if should_update_object_id_index
218
222
  operations << { action: 'clear', indexName: index_object_ids.name }
219
223
  local_ids.each_slice(100).each do |ids|
220
224
  operations << {
@@ -356,7 +360,8 @@ module Jekyll
356
360
  end
357
361
  Logger.known_message(
358
362
  'settings_manually_edited',
359
- settings: yaml_lines.join("\n")
363
+ settings: yaml_lines.join("\n"),
364
+ index_name: Configurator.index_name
360
365
  )
361
366
  end
362
367
 
@@ -130,6 +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 make them fit under 10Kb
134
+ # We take into account the objectID that will be added in the form of:
135
+ # "objectID": "16cd998991cc40d92402b0b4e6c55e8a"
136
+ object_id_attribute_length = 46
137
+ max_file_size = 10_000 - object_id_attribute_length
138
+ records.map! do |record|
139
+ Shrinker.fit_to_size(record, max_file_size)
140
+ end
141
+
133
142
  # Adding a unique objectID to each record
134
143
  records.map! do |record|
135
144
  Extractor.add_unique_object_id(record)
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ module Jekyll
5
+ module Algolia
6
+ # Module to shrink a record so it fits in the plan quotas
7
+ module Shrinker
8
+ include Jekyll::Algolia
9
+
10
+ # Public: Get the byte size of the object once converted to JSON
11
+ # - record: The record to estimate
12
+ def self.size(record)
13
+ record.to_json.length
14
+ end
15
+
16
+ # Public: Attempt to reduce the size of the record by reducing the size of
17
+ # the less needed attributes
18
+ #
19
+ # - raw_record: The record to attempt to reduce
20
+ # - max_size: The max size to achieve in bytes
21
+ #
22
+ # The excerpts are the attributes most subject to being reduced. We'll go
23
+ # as far as removing them if there is no other choice.
24
+ def self.fit_to_size(raw_record, max_size)
25
+ return raw_record if size(raw_record) <= max_size
26
+
27
+ # No excerpt, we can't shrink it
28
+ return raw_record unless raw_record.key?(:excerpt_html)
29
+
30
+ record = raw_record.clone
31
+
32
+ # We replace the HTML excerpt with the textual one
33
+ record[:excerpt_html] = record[:excerpt_text]
34
+ return record if size(record) <= max_size
35
+
36
+ # We halve the excerpts
37
+ excerpt_words = record[:excerpt_text].split(/\s+/)
38
+ shortened_excerpt = excerpt_words[0...excerpt_words.size / 2].join(' ')
39
+ record[:excerpt_text] = shortened_excerpt
40
+ record[:excerpt_html] = shortened_excerpt
41
+ return record if size(record) <= max_size
42
+
43
+ # We remove the excerpts completely
44
+ record[:excerpt_text] = nil
45
+ record[:excerpt_html] = nil
46
+
47
+ record
48
+ end
49
+ end
50
+ end
51
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Algolia
5
- VERSION = '1.3.4'
5
+ VERSION = '1.4.0'
6
6
  end
7
7
  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.3.4
4
+ version: 1.4.0
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-04-12 00:00:00.000000000 Z
11
+ date: 2018-04-26 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.5.2
19
+ version: 2.6.1
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.5.2
26
+ version: 2.6.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: algoliasearch
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -308,6 +308,7 @@ files:
308
308
  - lib/jekyll/algolia/overwrites/jekyll-document.rb
309
309
  - lib/jekyll/algolia/overwrites/jekyll-tags-link.rb
310
310
  - lib/jekyll/algolia/progress_bar.rb
311
+ - lib/jekyll/algolia/shrinker.rb
311
312
  - lib/jekyll/algolia/utils.rb
312
313
  - lib/jekyll/algolia/version.rb
313
314
  - lib/jekyll/commands/algolia.rb