slate_algolia 1.0.0 → 1.1.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: d7501fd269fa65aa278b4e78674e7fcb2236ac63
4
- data.tar.gz: b181aa3c1968582c0a5b817cd5ee9c99bb042b57
3
+ metadata.gz: 9e693364fa66ed8b1e5e8caa61a3c79e57f59074
4
+ data.tar.gz: d2890cdd992f6431d2181d9086a4a334f4b637b8
5
5
  SHA512:
6
- metadata.gz: d05ec3b8c68eec7f1ec8bf1c1fb22665374bbcafaa364feaa93fd9a2e5da07af5dd304a936faf92317bad3c1f1e393b934c6880811138a8dde3b0ef99d48b20f
7
- data.tar.gz: b79afe1e0dbf732f73fdb56c307317170b3bb3c00619ae2acaddc2bc3ab0cf714d930346d3474086199c9931be21c655a29e95bd259930ebab983dea92565e43
6
+ metadata.gz: be41497f30abeb8a40633d7f7b8071e2345efad566e58a15b4a92aade85c403a32b4c57de76ea3b41699af3da365ac3744aedee03b317c5a4d70506dd07c3244
7
+ data.tar.gz: ddd4a293de3822fc42399e4a93c1314efbb00e62f28e967afaddc8d8dbd789a265c33066c4790555eeee3c7b22c03f0237020068780f4ee2686f6ee9a5eb04eb
data/README.md CHANGED
@@ -87,6 +87,22 @@ activate :slate_algolia do |options|
87
87
  end
88
88
  ```
89
89
 
90
+ ## Filtering Deletes
91
+
92
+ `slate_algolia` has automatic cleanup built in - meaning that after indexing new content, it will look through Algolia for any content that exists there but **does not** exist in the current content. It will remove those items, assuming they have been removed from the active content. However, you may not want to delete all of your unmatched records - perhaps they serve as a good synonym, or perhaps you index more than just slate docs in that Algolia index. There is a hook option you can use the filter out records from being deleted.
93
+
94
+ ```ruby
95
+ activate :slate_algolia do |options|
96
+ options.filter_deletes = proc { |record|
97
+ if record['category'] == 'API Docs'
98
+ true # Truthy values will be deleted
99
+ else
100
+ false # Non-Truthy values will be ignored
101
+ end
102
+ }
103
+ end
104
+ ```
105
+
90
106
 
91
107
  ## Custom Tag Parser
92
108
 
@@ -12,6 +12,7 @@ module Middleman
12
12
  option :index_name, 'API Docs', 'Name for the Algolia Index'
13
13
  option :api_key, '', 'Algolia API Key'
14
14
  option :before_index, nil, 'A block to run on each record before it is sent to the index'
15
+ option :filter_deletes, nil, 'A block to run on each record before it is deleted from the index'
15
16
 
16
17
  def initialize(app, options_hash = {}, &block)
17
18
  super
@@ -30,7 +31,8 @@ module Middleman
30
31
  api_key: options.api_key,
31
32
  name: options.index_name,
32
33
  dry_run: options.dry_run,
33
- before_index: options.before_index
34
+ before_index: options.before_index,
35
+ filter_deletes: options.filter_deletes
34
36
  )
35
37
  end
36
38
 
@@ -24,7 +24,11 @@ module Middleman
24
24
 
25
25
  def clean_index
26
26
  old_content = @index.browse['hits'].reject do |hit|
27
- @published.any? { |entry| entry[:id] == hit['id'] }
27
+ @published.any? { |entry| entry[:id] == hit['objectID'] }
28
+ end
29
+
30
+ if @options[:filter_deletes].instance_of?(Proc)
31
+ old_content = run_filter_delete(old_content)
28
32
  end
29
33
 
30
34
  if @publish
@@ -49,6 +53,10 @@ module Middleman
49
53
  @queue.flatten!
50
54
  end
51
55
 
56
+ def run_filter_delete(all_records)
57
+ return all_records.select(&@options[:filter_deletes])
58
+ end
59
+
52
60
  def flush_queue
53
61
  run_before_index
54
62
 
@@ -3,7 +3,7 @@ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'slate_algolia'
6
- s.version = '1.0.0'
6
+ s.version = '1.1.0'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ['Joe Wegner']
9
9
  s.email = ['joe@wegnerdesign.com']
@@ -16,5 +16,5 @@ Gem::Specification.new do |s|
16
16
  # The version of middleman-core your extension depends on
17
17
  s.add_runtime_dependency('middleman-core', ['~> 3.3', '>= 3.3.12'])
18
18
  s.add_runtime_dependency('oga', ['~> 1.3', '>= 1.3.1'])
19
- s.add_runtime_dependency('algoliasearch', ['~> 1.6', '>= 1.6.1'])
19
+ s.add_runtime_dependency('algoliasearch', ['~> 1.12', '>= 1.12.5'])
20
20
  end
@@ -7,7 +7,8 @@ describe Middleman::SlateAlgolia::Extension do
7
7
  :dry_run,
8
8
  :index_name,
9
9
  :parsers,
10
- :before_index
10
+ :before_index,
11
+ :filter_deletes
11
12
  )
12
13
 
13
14
  default_options = ConfigOptions.new('', '', false, 'API Docs', {}, nil)
data/spec/index_spec.rb CHANGED
@@ -128,4 +128,36 @@ describe Middleman::SlateAlgolia::Index do
128
128
  index.flush_queue
129
129
  end
130
130
  end
131
+
132
+ describe 'clean_index' do
133
+ it 'selects records using the :filter_deletes hook' do
134
+ index = Middleman::SlateAlgolia::Index.new(
135
+ application_id: '',
136
+ api_key: '',
137
+ dry_run: false,
138
+ filter_deletes: proc do |record|
139
+ record['objectID'] == "1"
140
+ end
141
+ )
142
+
143
+ instance_index = index.instance_variable_get('@index')
144
+
145
+ expect(instance_index).to receive(:delete_objects)
146
+ .with(['1'])
147
+ allow(instance_index).to receive(:browse) {
148
+ {
149
+ 'hits' => [
150
+ {
151
+ 'objectID' => '1'
152
+ },
153
+ {
154
+ 'objectID' => '2'
155
+ }
156
+ ]
157
+ }
158
+ }
159
+
160
+ index.clean_index
161
+ end
162
+ end
131
163
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slate_algolia
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Wegner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-28 00:00:00.000000000 Z
11
+ date: 2017-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman-core
@@ -56,20 +56,20 @@ dependencies:
56
56
  requirements:
57
57
  - - "~>"
58
58
  - !ruby/object:Gem::Version
59
- version: '1.6'
59
+ version: '1.12'
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
- version: 1.6.1
62
+ version: 1.12.5
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '1.6'
69
+ version: '1.12'
70
70
  - - ">="
71
71
  - !ruby/object:Gem::Version
72
- version: 1.6.1
72
+ version: 1.12.5
73
73
  description:
74
74
  email:
75
75
  - joe@wegnerdesign.com