jekyll-algolia 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Algolia
5
+ # Display helpful error messages
6
+ module Logger
7
+ # Public: Displays a log line
8
+ #
9
+ # line - Line to display. Expected to be of the following format:
10
+ # "X:Your content"
11
+ # Where X is either I, W or E for marking respectively an info, warning or
12
+ # error display
13
+ def self.log(line)
14
+ type, content = /^(I|W|E):(.*)/.match(line).captures
15
+ logger_mapping = {
16
+ 'E' => :error,
17
+ 'I' => :info,
18
+ 'W' => :warn
19
+ }
20
+
21
+ # Jekyll logger tries to center log lines, so we force a consistent
22
+ # width of 80 chars
23
+ content = content.ljust(80, ' ')
24
+ Jekyll.logger.send(logger_mapping[type], content)
25
+ end
26
+
27
+ # Public: Only display a log line if verbose mode is enabled
28
+ #
29
+ # line - The line to display, following the same format as .log
30
+ def self.verbose(line)
31
+ return unless Configurator.verbose?
32
+ log(line)
33
+ end
34
+
35
+ # Public: Displays a helpful error message for one of the knows errors
36
+ #
37
+ # message_id: A string identifying a know message
38
+ # metadata: Hash of variables that can be used in the final text
39
+ #
40
+ # It will read files in ./errors/*.txt with the matching error and
41
+ # display them using Jekyll internal logger.
42
+ def self.known_message(message_id, metadata = {})
43
+ file = File.expand_path(
44
+ File.join(
45
+ __dir__, '../../..', 'errors', "#{message_id}.txt"
46
+ )
47
+ )
48
+
49
+ # Convert all variables
50
+ content = File.open(file).read
51
+ metadata.each do |key, value|
52
+ content = content.gsub("{#{key}}", value)
53
+ end
54
+
55
+ # Display each line differently
56
+ lines = content.each_line.map(&:chomp)
57
+ lines.each do |line|
58
+ log(line)
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'nokogiri'
4
+
5
+ module Jekyll
6
+ module Algolia
7
+ # Generic language-wide utils
8
+ module Utils
9
+ # Public: Convert a hash with string keys to a hash with symbol keys
10
+ #
11
+ # hash - The input hash, with string keys
12
+ def self.keys_to_symbols(hash)
13
+ Hash[hash.map { |key, value| [key.to_sym, value] }]
14
+ end
15
+
16
+ # Public: Convert an HTML string to its content only
17
+ #
18
+ # html - String representation of the HTML node
19
+ def self.html_to_text(html)
20
+ text = Nokogiri::HTML(html).text
21
+ text.tr("\n", ' ').squeeze(' ').strip
22
+ end
23
+
24
+ # Public: Remove all keys with a nil value or an empty array from a hash
25
+ #
26
+ # hash - The input hash
27
+ def self.compact_empty(hash)
28
+ new_hash = {}
29
+ hash.each do |key, value|
30
+ next if value.nil?
31
+ next if value.respond_to?(:empty?) && value.empty?
32
+ new_hash[key] = value
33
+ end
34
+ new_hash
35
+ end
36
+
37
+ # Public: Check if a string matches a regex
38
+ #
39
+ # string - The string to test
40
+ # regex - The regex to match against
41
+ #
42
+ # Newer versions of Ruby have easy ways to test this, but a wrapper is
43
+ # needed for older versions.
44
+ def self.match?(string, regex)
45
+ # Ruby 2.4 introduces .match?
46
+ return regex.match?(string) if regex.respond_to?(:match?)
47
+
48
+ # Older versions of Ruby have to deal with =~ returning nil if no match
49
+ # is found
50
+ !(string =~ regex).nil?
51
+ end
52
+
53
+ # Public: Find an item from an array based on the value of one of its key
54
+ #
55
+ # items - The array of hashes to search
56
+ # key - The key to search for
57
+ # value - The value of the key to filter
58
+ #
59
+ # It is basically a wrapper around [].find, handling more edge-cases
60
+ def self.find_by_key(items, key, value)
61
+ return nil if items.nil?
62
+ items.find do |item|
63
+ item[key] == value
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Algolia
5
+ VERSION = '0.0.0'
6
+ end
7
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Commands
5
+ # Registering the `jekyll algolia` command
6
+ class Algolia < Command
7
+ class << self
8
+ def init_with_program(prog)
9
+ prog.command(:algolia) do |command|
10
+ command.syntax 'algolia [options]'
11
+ command.description 'Push your content to an Algolia index'
12
+ # Document the options that can be passed from the CLI
13
+ command.option 'config',
14
+ '--config CONFIG_FILE[,CONFIG_FILE2,...]',
15
+ Array,
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
+ command.option 'dry_run',
32
+ '--dry-run',
33
+ '-n',
34
+ 'Do a dry run, do not push records'
35
+ command.option 'verbose',
36
+ '--verbose',
37
+ 'Display more information on what is indexed'
38
+
39
+ command.action do |_, options|
40
+ configuration = configuration_from_options(options)
41
+
42
+ Jekyll::Algolia.init(configuration).run
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
metadata ADDED
@@ -0,0 +1,304 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-algolia
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Tim Carry
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: algolia_html_extractor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: algoliasearch
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.18'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.18'
41
+ - !ruby/object:Gem::Dependency
42
+ name: filesize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: jekyll
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: jekyll-paginate
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.1'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: json
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: nokogiri
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.6'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.6'
111
+ - !ruby/object:Gem::Dependency
112
+ name: verbal_expressions
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.1.5
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.1.5
125
+ - !ruby/object:Gem::Dependency
126
+ name: coveralls
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.8'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.8'
139
+ - !ruby/object:Gem::Dependency
140
+ name: flay
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '2.6'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '2.6'
153
+ - !ruby/object:Gem::Dependency
154
+ name: flog
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '4.3'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '4.3'
167
+ - !ruby/object:Gem::Dependency
168
+ name: guard-rspec
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '4.6'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '4.6'
181
+ - !ruby/object:Gem::Dependency
182
+ name: rake
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '12.3'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '12.3'
195
+ - !ruby/object:Gem::Dependency
196
+ name: rspec
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: '3.0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: '3.0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: rubocop
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - "~>"
214
+ - !ruby/object:Gem::Version
215
+ version: '0.51'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - "~>"
221
+ - !ruby/object:Gem::Version
222
+ version: '0.51'
223
+ - !ruby/object:Gem::Dependency
224
+ name: rubocop-rspec-focused
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - "~>"
228
+ - !ruby/object:Gem::Version
229
+ version: 0.1.0
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - "~>"
235
+ - !ruby/object:Gem::Version
236
+ version: 0.1.0
237
+ - !ruby/object:Gem::Dependency
238
+ name: simplecov
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - "~>"
242
+ - !ruby/object:Gem::Version
243
+ version: '0.10'
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - "~>"
249
+ - !ruby/object:Gem::Version
250
+ version: '0.10'
251
+ description: Index all your content into Algolia by running `jekyll algolia`
252
+ email: tim@pixelastic.com
253
+ executables: []
254
+ extensions: []
255
+ extra_rdoc_files: []
256
+ files:
257
+ - CONTRIBUTING.md
258
+ - 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
269
+ - lib/jekyll-algolia.rb
270
+ - lib/jekyll/algolia/configurator.rb
271
+ - lib/jekyll/algolia/error_handler.rb
272
+ - lib/jekyll/algolia/extractor.rb
273
+ - lib/jekyll/algolia/file_browser.rb
274
+ - lib/jekyll/algolia/hooks.rb
275
+ - lib/jekyll/algolia/indexer.rb
276
+ - lib/jekyll/algolia/logger.rb
277
+ - lib/jekyll/algolia/utils.rb
278
+ - lib/jekyll/algolia/version.rb
279
+ - lib/jekyll/commands/algolia.rb
280
+ homepage: https://github.com/algolia/jekyll-algolia
281
+ licenses:
282
+ - MIT
283
+ metadata: {}
284
+ post_install_message:
285
+ rdoc_options: []
286
+ require_paths:
287
+ - lib
288
+ required_ruby_version: !ruby/object:Gem::Requirement
289
+ requirements:
290
+ - - ">="
291
+ - !ruby/object:Gem::Version
292
+ version: 2.3.0
293
+ required_rubygems_version: !ruby/object:Gem::Requirement
294
+ requirements:
295
+ - - ">="
296
+ - !ruby/object:Gem::Version
297
+ version: '0'
298
+ requirements: []
299
+ rubyforge_project:
300
+ rubygems_version: 2.6.13
301
+ signing_key:
302
+ specification_version: 4
303
+ summary: Index your Jekyll content into Algolia
304
+ test_files: []