algoliasearch-jekyll 0.7.0 → 0.8.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c1ea0f7d0eecf20f9cb33f30116df426637a9f4
4
- data.tar.gz: 8ec5644ebbd8c08fcead43c3c6cf64c0bbe82db6
3
+ metadata.gz: 2ebfd20e06b278a2b943b37c75d7b3075779f48d
4
+ data.tar.gz: 2272b59b28c71753e7b7e15ade27807fcb8feaf4
5
5
  SHA512:
6
- metadata.gz: 0dd5939456e660845ec71719c47ea296088284907b8d58b3d7ac08e5b070ac6dc688edcd18030e0bb87efe2b62a655c71ffb393f81e674936235cf16a9a46ccb
7
- data.tar.gz: d19157c6ba465da2dea75f62e4744d3b55fb170043c7aedd0098f7b37bba2d53bb00b4fc2ade9458a1c716340e103768a16381a44052245400089787a3781853
6
+ metadata.gz: 324e688e2753917e29d652832162e7feca773f2461681cc7cdcd008a36e735321c5d641448ecd7e497af4e551be66ec032446a2fc9340aa4bde71cfb4936499d
7
+ data.tar.gz: 90fcc05cc357873eb8b49ba3c8d35c5e2e00aaf796e762726c9b66f9e27e6aae3dd9caa8d42f6b42f5bd3c81ce497716e20a4b0e6f2c41a0063162efc119799d
data/README.md CHANGED
@@ -12,7 +12,7 @@ Algolia index by simply running `jekyll algolia push`.
12
12
  ## Usage
13
13
 
14
14
  ```shell
15
- $ jekyll algolia push
15
+ $ bundle exec jekyll algolia push
16
16
  ```
17
17
 
18
18
  This will push the content of your jekyll website to your Algolia index.
@@ -32,7 +32,7 @@ source 'https://rubygems.org'
32
32
  gem 'jekyll', '~> 2.5.3'
33
33
 
34
34
  group :jekyll_plugins do
35
- gem 'algoliasearch-jekyll', '~> 0.5.3'
35
+ gem 'algoliasearch-jekyll', '~> 0.7.0'
36
36
  end
37
37
  ```
38
38
 
@@ -60,6 +60,10 @@ algolia:
60
60
  index_name: 'your_index_name'
61
61
  ```
62
62
 
63
+ You can also define the `ALGOLIA_APPLICATION_ID` and `ALGOLIA_INDEX_NAME`
64
+ environment variables. If present, they will be used instead of the options in
65
+ `_config.yml`.
66
+
63
67
  You write api key will be read from the `ALGOLIA_API_KEY` environment variable.
64
68
  You can define it on the same line as your command, allowing you to type
65
69
  `ALGOLIA_API_KEY='your_write_api_key' jekyll algolia push`.
@@ -149,11 +153,17 @@ The `AlgoliaSearchRecordExtractor` contains two methods (`custom_hook_each` and
149
153
  `custom_hook_all`) that are here so you can overwrite them to add your custom
150
154
  logic. They currently simply return the argument they take as input.
151
155
 
156
+ The best way to override them is to create a `./_plugins/search.rb` file, with
157
+ the following content:
158
+
152
159
  ```ruby
153
160
  class AlgoliaSearchRecordExtractor
154
161
  # Hook to modify a record after extracting
155
- # `node` refers to the Nokogiri HTML node of the element
156
162
  def custom_hook_each(item, node)
163
+ # `node` is a Nokogiri HTML node, so you can access its type through `node.name`
164
+ # or its classname through `node.attr('class')` for example
165
+
166
+ # Just return `nil` instead of `item` if you want to discard this record
157
167
  item
158
168
  end
159
169
 
@@ -210,8 +220,8 @@ version of the popular [Hyde theme][8].
210
220
  ## GitHub Pages
211
221
 
212
222
  GitHub does not allow custom plugins to be run on GitHub Pages. This means that
213
- you'll either have to run `jekyll algolia push` manually, or configure TravisCI
214
- to do it for you.
223
+ you'll either have to run `bundle exec jekyll algolia push` manually, or
224
+ configure TravisCI to do it for you.
215
225
 
216
226
  [Travis CI][9] is an hosted continuous integration
217
227
  service, and it's free for open-source projects. Properly configured, it can
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: algoliasearch-jekyll 0.7.0 ruby lib
5
+ # stub: algoliasearch-jekyll 0.8.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "algoliasearch-jekyll"
9
- s.version = "0.7.0"
9
+ s.version = "0.8.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Tim Carry"]
14
- s.date = "2016-03-08"
14
+ s.date = "2016-07-13"
15
15
  s.description = "Index all your pages and posts to an Algolia index with `jekyll algolia push`"
16
16
  s.email = "tim@pixelastic.com"
17
17
  s.extra_rdoc_files = [
@@ -26,6 +26,29 @@ class AlgoliaSearchCredentialChecker
26
26
  nil
27
27
  end
28
28
 
29
+ # Read key either from ENV or _config.yml
30
+ def get_key(env_name, config_key)
31
+ # First read in ENV
32
+ return ENV[env_name] if ENV[env_name]
33
+
34
+ # Otherwise read from _config.yml
35
+ if @config['algolia'] && @config['algolia'][config_key]
36
+ return @config['algolia'][config_key]
37
+ end
38
+
39
+ nil
40
+ end
41
+
42
+ # Read the application id either from the config file or from ENV
43
+ def application_id
44
+ get_key('ALGOLIA_APPLICATION_ID', 'application_id')
45
+ end
46
+
47
+ # Read the index name either from the config file or from ENV
48
+ def index_name
49
+ get_key('ALGOLIA_INDEX_NAME', 'index_name')
50
+ end
51
+
29
52
  # Check that the API key is available
30
53
  def check_api_key
31
54
  return if api_key
@@ -35,14 +58,14 @@ class AlgoliaSearchCredentialChecker
35
58
 
36
59
  # Check that the application id is defined
37
60
  def check_application_id
38
- return if @config['algolia'] && @config['algolia']['application_id']
61
+ return if application_id
39
62
  @logger.display('application_id_missing')
40
63
  exit 1
41
64
  end
42
65
 
43
66
  # Check that the index name is defined
44
67
  def check_index_name
45
- return if @config['algolia'] && @config['algolia']['index_name']
68
+ return if index_name
46
69
  @logger.display('index_name_missing')
47
70
  exit 1
48
71
  end
@@ -55,7 +78,7 @@ class AlgoliaSearchCredentialChecker
55
78
  check_index_name
56
79
 
57
80
  Algolia.init(
58
- application_id: @config['algolia']['application_id'],
81
+ application_id: application_id,
59
82
  api_key: api_key
60
83
  )
61
84
 
data/lib/push.rb CHANGED
@@ -176,12 +176,13 @@ class AlgoliaSearchJekyllPush < Jekyll::Command
176
176
  end
177
177
 
178
178
  def push(items)
179
- AlgoliaSearchCredentialChecker.new(@config).assert_valid
179
+ checker = AlgoliaSearchCredentialChecker.new(@config)
180
+ checker.assert_valid
180
181
 
181
182
  Jekyll.logger.info '=== DRY RUN ===' if @is_dry_run
182
183
 
183
184
  # Add items to a temp index, then rename it
184
- index_name = @config['algolia']['index_name']
185
+ index_name = checker.index_name
185
186
  index_name_tmp = "#{index_name}_tmp"
186
187
  batch_add_items(items, create_index(index_name_tmp))
187
188
  Algolia.move_index(index_name_tmp, index_name) unless @is_dry_run
data/lib/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # Expose gem version
2
2
  class AlgoliaSearchJekyllVersion
3
3
  def self.to_s
4
- '0.7.0'
4
+ '0.8.0'
5
5
  end
6
6
  end
@@ -59,6 +59,130 @@ describe(AlgoliaSearchCredentialChecker) do
59
59
  end
60
60
  end
61
61
 
62
+ describe 'check_api_key' do
63
+ it 'should exit with error if no API key' do
64
+ # Given
65
+ allow(checker).to receive(:api_key).and_return(nil)
66
+ allow(checker.logger).to receive(:display)
67
+
68
+ # When / Then
69
+ expect(-> { checker.check_api_key }).to raise_error SystemExit
70
+ end
71
+
72
+ it 'should do nothing when an API key is found' do
73
+ # Given
74
+ allow(checker).to receive(:api_key).and_return('APIKEY')
75
+
76
+ # When / Then
77
+ expect(-> { checker.check_api_key }).not_to raise_error
78
+ end
79
+ end
80
+
81
+ describe 'application_id' do
82
+ it 'reads value from the _config.yml file' do
83
+ # Given
84
+
85
+ # When
86
+ actual = checker.application_id
87
+
88
+ # Then
89
+ expect(actual).to eq 'APPID'
90
+ end
91
+
92
+ it 'reads from ENV var if set' do
93
+ # Given
94
+ stub_const('ENV', 'ALGOLIA_APPLICATION_ID' => 'APPLICATION_ID_FROM_ENV')
95
+
96
+ # When
97
+ actual = checker.application_id
98
+
99
+ # Then
100
+ expect(actual).to eq 'APPLICATION_ID_FROM_ENV'
101
+ end
102
+
103
+ it 'returns nil if no key found' do
104
+ # Given
105
+ config['algolia']['application_id'] = nil
106
+
107
+ # When
108
+ actual = checker.application_id
109
+
110
+ # Then
111
+ expect(actual).to be_nil
112
+ end
113
+ end
114
+
115
+ describe 'check_application_id' do
116
+ it 'should exit with error if no application ID' do
117
+ # Given
118
+ allow(checker).to receive(:application_id).and_return(nil)
119
+ allow(checker.logger).to receive(:display)
120
+
121
+ # When / Then
122
+ expect(-> { checker.check_application_id }).to raise_error SystemExit
123
+ end
124
+
125
+ it 'should do nothing when an application ID is found' do
126
+ # Given
127
+ allow(checker).to receive(:application_id).and_return('APPLICATIONID')
128
+
129
+ # When / Then
130
+ expect(-> { checker.check_application_id }).not_to raise_error
131
+ end
132
+ end
133
+
134
+ describe 'index_name' do
135
+ it 'reads value from the _config.yml file' do
136
+ # Given
137
+
138
+ # When
139
+ actual = checker.index_name
140
+
141
+ # Then
142
+ expect(actual).to eq 'INDEXNAME'
143
+ end
144
+
145
+ it 'reads from ENV var if set' do
146
+ # Given
147
+ stub_const('ENV', 'ALGOLIA_INDEX_NAME' => 'INDEX_NAME_FROM_ENV')
148
+
149
+ # When
150
+ actual = checker.index_name
151
+
152
+ # Then
153
+ expect(actual).to eq 'INDEX_NAME_FROM_ENV'
154
+ end
155
+
156
+ it 'returns nil if no key found' do
157
+ # Given
158
+ config['algolia']['index_name'] = nil
159
+
160
+ # When
161
+ actual = checker.index_name
162
+
163
+ # Then
164
+ expect(actual).to be_nil
165
+ end
166
+ end
167
+ describe 'check_index_name' do
168
+ it 'should exit with error if no index name' do
169
+ # Given
170
+ allow(checker).to receive(:index_name).and_return(nil)
171
+ allow(checker.logger).to receive(:display)
172
+
173
+ # When / Then
174
+ expect(-> { checker.check_index_name }).to raise_error SystemExit
175
+ end
176
+
177
+ it 'should do nothing when an index name is found' do
178
+ # Given
179
+ allow(checker).to receive(:index_name).and_return('INDEXNAME')
180
+
181
+ # When / Then
182
+ expect(-> { checker.check_index_name }).not_to raise_error
183
+ end
184
+ end
185
+
62
186
  describe 'assert_valid' do
63
187
  before(:each) do
64
188
  allow(checker.logger).to receive(:display)
@@ -104,7 +228,8 @@ describe(AlgoliaSearchCredentialChecker) do
104
228
 
105
229
  it 'should init the Algolia client' do
106
230
  # Given
107
- stub_const('ENV', 'ALGOLIA_API_KEY' => 'APIKEY_FROM_ENV')
231
+ allow(checker).to receive(:application_id).and_return('FOO')
232
+ allow(checker).to receive(:api_key).and_return('BAR')
108
233
  allow(Algolia).to receive(:init)
109
234
 
110
235
  # When
@@ -112,8 +237,8 @@ describe(AlgoliaSearchCredentialChecker) do
112
237
 
113
238
  # Then
114
239
  expect(Algolia).to have_received(:init).with(
115
- application_id: 'APPID',
116
- api_key: 'APIKEY_FROM_ENV'
240
+ application_id: 'FOO',
241
+ api_key: 'BAR'
117
242
  )
118
243
  end
119
244
  end
data/spec/spec_helper.rb CHANGED
@@ -26,7 +26,7 @@ def get_site(config = {}, options = {})
26
26
  options = default_options.merge(options)
27
27
 
28
28
  config = config.merge(
29
- source: fixture_path
29
+ 'source' => fixture_path
30
30
  )
31
31
  config = Jekyll.configuration(config)
32
32
 
@@ -4,5 +4,7 @@ Algolia Error: No application ID defined
4
4
  algolia:
5
5
  application_id: {your_application_id}
6
6
 
7
+ You can also define the ALGOLIA_APPLICATION_ID environment variable.
8
+
7
9
  Your application ID can be found in your algolia dashboard:
8
10
  https://www.algolia.com/licensing
@@ -4,6 +4,8 @@ Algolia Error: No index name defined
4
4
  algolia:
5
5
  index_name: {your_index_name}
6
6
 
7
+ You can also define the ALGOLIA_INDEX_NAME environment variable.
8
+
7
9
  You can edit your indices in your dashboard:
8
10
  https://www.algolia.com/explorer
9
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: algoliasearch-jekyll
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.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: 2016-03-08 00:00:00.000000000 Z
11
+ date: 2016-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: algoliasearch