jekyll-algolia 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/errors/no_records_found.txt +1 -1
- data/lib/jekyll-algolia.rb +2 -12
- data/lib/jekyll/algolia/configurator.rb +60 -2
- data/lib/jekyll/algolia/file_browser.rb +7 -59
- data/lib/jekyll/algolia/utils.rb +33 -0
- data/lib/jekyll/algolia/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a394d33bddf856fafbb84d345f2a87987583757b
|
4
|
+
data.tar.gz: eaeaa8ff67fdfda25d94e312cdcc18d21510c9a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db3edbb0a108e58ceddc7c9c1b6aaafe9747d968b007e4b9a25c58ee7a878035282e8452ee826b57d26a503c247667fccdae991222ffc7d4aa28aa055876bb37
|
7
|
+
data.tar.gz: 24f04bf128f70fe949f8bc27f59e3ac39cb172771dab6365205c0716cc92434e5e4d6d62f46b0c25368031db28d11944f9c065377ef1e92c6af11cf90e84e9c2
|
@@ -10,7 +10,7 @@ I: `files_to_exclude` option. You are currently excluding the following files:
|
|
10
10
|
I: {files_to_exclude}
|
11
11
|
I:
|
12
12
|
I: Also double check that your current value for `nodes_to_index` can actually
|
13
|
-
I: match something in the
|
13
|
+
I: match something in the pages. You are current indexing the following nodes:
|
14
14
|
I: {nodes_to_index}
|
15
15
|
I:
|
16
16
|
I: Note that all the markup that is defined in the layouts won't be available
|
data/lib/jekyll-algolia.rb
CHANGED
@@ -17,8 +17,6 @@ module Jekyll
|
|
17
17
|
require 'jekyll/algolia/extractor'
|
18
18
|
require 'jekyll/algolia/indexer'
|
19
19
|
|
20
|
-
@config = {}
|
21
|
-
|
22
20
|
# Public: Init the Algolia module
|
23
21
|
#
|
24
22
|
# config - A hash of Jekyll config option (merge of _config.yml options and
|
@@ -27,9 +25,9 @@ module Jekyll
|
|
27
25
|
# The gist of the plugin works by instanciating a Jekyll site,
|
28
26
|
# monkey-patching its `write` method and building it.
|
29
27
|
def self.init(config = {})
|
30
|
-
@config = config
|
31
28
|
@start_time = Time.now
|
32
|
-
|
29
|
+
config = Configurator.init(config).config
|
30
|
+
@site = Jekyll::Algolia::Site.new(config)
|
33
31
|
|
34
32
|
exit 1 unless Configurator.assert_valid_credentials
|
35
33
|
|
@@ -57,14 +55,6 @@ module Jekyll
|
|
57
55
|
@site.process
|
58
56
|
end
|
59
57
|
|
60
|
-
# Public: Get access to the Jekyll config
|
61
|
-
#
|
62
|
-
# All other classes will need access to this config, so we make it publicly
|
63
|
-
# accessible
|
64
|
-
def self.config
|
65
|
-
@config
|
66
|
-
end
|
67
|
-
|
68
58
|
# Public: Get access to the Jekyll site
|
69
59
|
#
|
70
60
|
# Tests will need access to the inner Jekyll website so we expose it here
|
@@ -6,6 +6,8 @@ module Jekyll
|
|
6
6
|
module Configurator
|
7
7
|
include Jekyll::Algolia
|
8
8
|
|
9
|
+
@config = {}
|
10
|
+
|
9
11
|
# Algolia default values
|
10
12
|
ALGOLIA_DEFAULTS = {
|
11
13
|
'extensions_to_index' => nil,
|
@@ -56,13 +58,37 @@ module Jekyll
|
|
56
58
|
}
|
57
59
|
}.freeze
|
58
60
|
|
61
|
+
# Public: Init the configurator with the Jekyll config
|
62
|
+
#
|
63
|
+
# config - The config passed by the `jekyll algolia` command. Default to
|
64
|
+
# the default Jekyll config
|
65
|
+
def self.init(config = nil)
|
66
|
+
# Use the default Jekyll configuration if none specified. Silence the
|
67
|
+
# warning about no config set
|
68
|
+
Logger.silent { config = Jekyll.configuration } if config.nil?
|
69
|
+
|
70
|
+
@config = config
|
71
|
+
@config['exclude'] = files_excluded_from_render
|
72
|
+
|
73
|
+
@config = disable_other_plugins(@config)
|
74
|
+
|
75
|
+
self
|
76
|
+
end
|
77
|
+
|
78
|
+
# Public: Access to the global configuration object
|
79
|
+
#
|
80
|
+
# This is a method around @config so we can mock it in the tests
|
81
|
+
def self.config
|
82
|
+
@config
|
83
|
+
end
|
84
|
+
|
59
85
|
# Public: Get the value of a specific Jekyll configuration option
|
60
86
|
#
|
61
87
|
# key - Key to read
|
62
88
|
#
|
63
89
|
# Returns the value of this configuration option, nil otherwise
|
64
90
|
def self.get(key)
|
65
|
-
|
91
|
+
config[key]
|
66
92
|
end
|
67
93
|
|
68
94
|
# Public: Get the value of a specific Algolia configuration option, or
|
@@ -149,7 +175,8 @@ module Jekyll
|
|
149
175
|
# Markdown files can have many different extensions. We keep the one
|
150
176
|
# defined in the Jekyll config
|
151
177
|
def self.default_extensions_to_index
|
152
|
-
|
178
|
+
markdown_ext = get('markdown_ext') || ''
|
179
|
+
['html'] + markdown_ext.split(',')
|
153
180
|
end
|
154
181
|
|
155
182
|
# Public: Setting a default value to ignore index.html/index.md files in
|
@@ -185,6 +212,37 @@ module Jekyll
|
|
185
212
|
false
|
186
213
|
end
|
187
214
|
|
215
|
+
# Public: List of files to exclude from the Jekyll build
|
216
|
+
#
|
217
|
+
# We skip all files usually ignored by Jekyll, plus any file that should
|
218
|
+
# not be indexed.
|
219
|
+
def self.files_excluded_from_render
|
220
|
+
site_exclude = get('exclude') || []
|
221
|
+
algolia_exclude = algolia('files_to_exclude') || []
|
222
|
+
|
223
|
+
excluded_files = site_exclude + algolia_exclude
|
224
|
+
|
225
|
+
# 404 pages are not Jekyll defaults but a convention adopted by GitHub
|
226
|
+
# pages. We don't want to index those.
|
227
|
+
# https://help.github.com/articles/creating-a-custom-404-page-for-your-github-pages-site/
|
228
|
+
excluded_files << '404.html'
|
229
|
+
excluded_files << '404.md'
|
230
|
+
|
231
|
+
excluded_files
|
232
|
+
end
|
233
|
+
|
234
|
+
# Public: Disable features from other Jekyll plugins that might interfere
|
235
|
+
# with the indexing
|
236
|
+
def self.disable_other_plugins(config)
|
237
|
+
# Disable pagination from jekyll-paginate
|
238
|
+
# It creates a lot of /page2/index.html files that are not relevant to
|
239
|
+
# indexing
|
240
|
+
# https://github.com/jekyll/jekyll-paginate/blob/master/lib/jekyll-paginate/pager.rb#L23
|
241
|
+
config['paginate'] = nil
|
242
|
+
|
243
|
+
config
|
244
|
+
end
|
245
|
+
|
188
246
|
# Public: Check for any deprecated config option and warn the user
|
189
247
|
def self.warn_of_deprecated_options
|
190
248
|
# indexing_mode is no longer used
|
@@ -34,7 +34,7 @@ module Jekyll
|
|
34
34
|
pathname = Pathname.new(file.path)
|
35
35
|
return pathname.cleanpath.to_s if pathname.absolute?
|
36
36
|
|
37
|
-
File.join(Configurator.get('source'), file.path)
|
37
|
+
File.expand_path(File.join(Configurator.get('source'), file.path))
|
38
38
|
end
|
39
39
|
|
40
40
|
# Public: Return the path of a Jekyll file relative to the Jekyll source
|
@@ -48,45 +48,12 @@ module Jekyll
|
|
48
48
|
pathname = Pathname.new(file.path)
|
49
49
|
return file.path if pathname.relative?
|
50
50
|
|
51
|
-
jekyll_source = Pathname.new(
|
51
|
+
jekyll_source = Pathname.new(
|
52
|
+
File.expand_path(Configurator.get('source'))
|
53
|
+
)
|
52
54
|
pathname.relative_path_from(jekyll_source).cleanpath.to_s
|
53
55
|
end
|
54
56
|
|
55
|
-
# Public: Check if the file is a 404 error page
|
56
|
-
#
|
57
|
-
# file - The Jekyll file
|
58
|
-
#
|
59
|
-
# 404 pages are not Jekyll defaults but a convention adopted by GitHub
|
60
|
-
# pages. We don't want to index those.
|
61
|
-
# Source: https://help.github.com/articles/creating-a-custom-404-page-for-your-github-pages-site/
|
62
|
-
#
|
63
|
-
# rubocop:disable Naming/PredicateName
|
64
|
-
def self.is_404?(file)
|
65
|
-
File.basename(file.path, File.extname(file.path)) == '404'
|
66
|
-
end
|
67
|
-
# rubocop:enable Naming/PredicateName
|
68
|
-
|
69
|
-
# Public: Check if the page is a pagination page
|
70
|
-
#
|
71
|
-
# file - The Jekyll file
|
72
|
-
#
|
73
|
-
# `jekyll-paginate` automatically creates pages to paginate through posts.
|
74
|
-
# We don't want to index those
|
75
|
-
def self.pagination_page?(file)
|
76
|
-
# paginate_path contains a special `:num` part that is the page number
|
77
|
-
# We convert that to a regexp
|
78
|
-
paginate_path = Configurator.get('paginate_path')
|
79
|
-
paginate_path_as_regexp = paginate_path.gsub(':num', '([0-9]*)')
|
80
|
-
|
81
|
-
regexp = %r{#{paginate_path_as_regexp}/index\.html$}
|
82
|
-
|
83
|
-
# Make sure all file paths start with a / for comparison
|
84
|
-
filepath = file.path
|
85
|
-
filepath = "/#{filepath}" unless filepath[0] == '/'
|
86
|
-
|
87
|
-
Utils.match?(filepath, regexp)
|
88
|
-
end
|
89
|
-
|
90
57
|
# Public: Check if the file has one of the allowed extensions
|
91
58
|
#
|
92
59
|
# file - The Jekyll file
|
@@ -101,16 +68,6 @@ module Jekyll
|
|
101
68
|
extensions.include?(extname)
|
102
69
|
end
|
103
70
|
|
104
|
-
# Public: Check if the file has been excluded by the user
|
105
|
-
#
|
106
|
-
# file - The Jekyll file
|
107
|
-
#
|
108
|
-
# Files can be excluded either by setting the `files_to_exclude` option,
|
109
|
-
# or by defining a custom hook
|
110
|
-
def self.excluded_by_user?(file)
|
111
|
-
excluded_from_config?(file) || excluded_from_hook?(file)
|
112
|
-
end
|
113
|
-
|
114
71
|
# Public: Check if the file has been excluded by `files_to_exclude`
|
115
72
|
#
|
116
73
|
# file - The Jekyll file
|
@@ -147,10 +104,8 @@ module Jekyll
|
|
147
104
|
# all the static assets, only keep the actual content.
|
148
105
|
def self.indexable?(file)
|
149
106
|
return false if static_file?(file)
|
150
|
-
return false if is_404?(file)
|
151
|
-
return false if pagination_page?(file)
|
152
107
|
return false unless allowed_extension?(file)
|
153
|
-
return false if
|
108
|
+
return false if excluded_from_hook?(file)
|
154
109
|
|
155
110
|
true
|
156
111
|
end
|
@@ -196,17 +151,10 @@ module Jekyll
|
|
196
151
|
data.each_key do |key|
|
197
152
|
data.delete(key) if respond_to?(key)
|
198
153
|
end
|
199
|
-
|
200
|
-
# Excerpt needs a special handling
|
201
154
|
data.delete('excerpt')
|
202
155
|
|
203
|
-
#
|
204
|
-
|
205
|
-
# object hash to change on each run. This causes the diff method to
|
206
|
-
# fail, so we discard this key.
|
207
|
-
if Utils.instance_of?(data['document'], 'Asciidoctor::Document')
|
208
|
-
data.delete('document')
|
209
|
-
end
|
156
|
+
# Convert all values to a version that can be serialized to JSON
|
157
|
+
data = Utils.jsonify(data)
|
210
158
|
|
211
159
|
# Convert all keys to symbols
|
212
160
|
data = Utils.keys_to_symbols(data)
|
data/lib/jekyll/algolia/utils.rb
CHANGED
@@ -88,6 +88,39 @@ module Jekyll
|
|
88
88
|
item[key] == value
|
89
89
|
end
|
90
90
|
end
|
91
|
+
|
92
|
+
# Public: Convert an object into an object that can easily be converted to
|
93
|
+
# JSON, to be stored as a record
|
94
|
+
#
|
95
|
+
# item - The object to convert
|
96
|
+
#
|
97
|
+
# It will keep any string, number, boolean,boolean,array or nested object,
|
98
|
+
# but will try to stringify other objects, excluding the one that contain
|
99
|
+
# a unique identifier once serialized.
|
100
|
+
def self.jsonify(item)
|
101
|
+
simple_types = [
|
102
|
+
NilClass,
|
103
|
+
TrueClass, FalseClass,
|
104
|
+
Integer, Float,
|
105
|
+
String
|
106
|
+
]
|
107
|
+
return item if simple_types.member?(item.class)
|
108
|
+
|
109
|
+
# Recursive types
|
110
|
+
return item.map { |value| jsonify(value) } if item.is_a?(Array)
|
111
|
+
if item.is_a?(Hash)
|
112
|
+
return item.map { |key, value| [key, jsonify(value)] }.to_h
|
113
|
+
end
|
114
|
+
|
115
|
+
# Can't be stringified, discard it
|
116
|
+
return nil unless item.respond_to?(:to_s)
|
117
|
+
|
118
|
+
# Discard also if is a serialized version with unique identifier
|
119
|
+
stringified = item.to_s
|
120
|
+
return nil if match?(stringified, /#<[^ ].*@[0-9]* .*>/)
|
121
|
+
|
122
|
+
stringified
|
123
|
+
end
|
91
124
|
end
|
92
125
|
end
|
93
126
|
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.1.
|
4
|
+
version: 1.1.3
|
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-02-
|
11
|
+
date: 2018-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: algolia_html_extractor
|
@@ -150,6 +150,20 @@ dependencies:
|
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '4.3'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: guard
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '2.14'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '2.14'
|
153
167
|
- !ruby/object:Gem::Dependency
|
154
168
|
name: guard-rspec
|
155
169
|
requirement: !ruby/object:Gem::Requirement
|