jekyll-algolia 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll-algolia.rb +6 -132
- data/lib/jekyll/algolia/overwrites/jekyll-algolia-site.rb +144 -0
- data/lib/jekyll/algolia/{overwrites.rb → overwrites/jekyll-document.rb} +0 -0
- data/lib/jekyll/algolia/overwrites/jekyll-tags-link.rb +33 -0
- data/lib/jekyll/algolia/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf886389ae5ad938db693d1bc2ed35e2b89015d3
|
4
|
+
data.tar.gz: 252509afafa7dd89faea1ed3dc7aa9590da1a9be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a4472b586bbd24f67ee82c4e1bdb8505789d50296b5604b4be388fa25df123545c5e949b8e7caada3276e28a4f1a9f0270a0ae5013f08d1c47d17df0238fc27
|
7
|
+
data.tar.gz: 78946a3ec46e391260479c1e2a24b131c3627d86f4b643f8e884b8cb183376317e95827600036b402c703ad2f796023d7f939777961ed809e70f40581b5f3221
|
data/lib/jekyll-algolia.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'jekyll/commands/algolia'
|
4
|
-
require 'jekyll/algolia/overwrites'
|
4
|
+
require 'jekyll/algolia/overwrites/jekyll-algolia-site'
|
5
|
+
require 'jekyll/algolia/overwrites/jekyll-document'
|
6
|
+
require 'jekyll/algolia/overwrites/jekyll-tags-link'
|
5
7
|
require 'date'
|
6
8
|
|
7
9
|
module Jekyll
|
@@ -34,6 +36,9 @@ module Jekyll
|
|
34
36
|
|
35
37
|
Configurator.warn_of_deprecated_options
|
36
38
|
|
39
|
+
# Register our own tags to overwrite the default tags
|
40
|
+
Liquid::Template.register_tag('link', JekyllAlgoliaLink)
|
41
|
+
|
37
42
|
if Configurator.dry_run?
|
38
43
|
Logger.log('W:==== THIS IS A DRY RUN ====')
|
39
44
|
Logger.log('W: - No records will be pushed to your index')
|
@@ -62,136 +67,5 @@ module Jekyll
|
|
62
67
|
def self.site
|
63
68
|
@site
|
64
69
|
end
|
65
|
-
|
66
|
-
# A Jekyll::Site subclass that overrides process from the parent class to
|
67
|
-
# create JSON records out of rendered documents and push those records to
|
68
|
-
# Algolia instead of writing files to disk.
|
69
|
-
class Site < Jekyll::Site
|
70
|
-
# We expose a way to reset the collection, as it will be needed in the
|
71
|
-
# tests
|
72
|
-
attr_writer :collections
|
73
|
-
|
74
|
-
# Public: Overwriting the parent method
|
75
|
-
#
|
76
|
-
# This will prepare the website, gathering all files, excluding the one we
|
77
|
-
# don't need to index, then render them (converting to HTML), the finally
|
78
|
-
# calling `push` to push to Algolia
|
79
|
-
def process
|
80
|
-
# Default Jekyll preflight
|
81
|
-
reset
|
82
|
-
read
|
83
|
-
generate
|
84
|
-
|
85
|
-
# Removing all files that won't be indexed, so we don't waste time
|
86
|
-
# rendering them
|
87
|
-
keep_only_indexable_files
|
88
|
-
|
89
|
-
# Starting the rendering progress bar
|
90
|
-
init_rendering_progress_bar
|
91
|
-
|
92
|
-
# Converting them to HTML
|
93
|
-
render
|
94
|
-
|
95
|
-
# Pushing them Algolia
|
96
|
-
push
|
97
|
-
end
|
98
|
-
|
99
|
-
# Public: Return the number of pages/documents to index
|
100
|
-
def indexable_item_count
|
101
|
-
count = @pages.length
|
102
|
-
@collections.each_value { |collection| count += collection.docs.length }
|
103
|
-
count
|
104
|
-
end
|
105
|
-
|
106
|
-
# Public: Init the rendering progress bar, incrementing it for each
|
107
|
-
# rendered item
|
108
|
-
#
|
109
|
-
# This uses Jekyll post_render hooks, listening to both pages and
|
110
|
-
# documents
|
111
|
-
def init_rendering_progress_bar
|
112
|
-
progress_bar = ProgressBar.create(
|
113
|
-
total: indexable_item_count,
|
114
|
-
format: 'Rendering to HTML (%j%%) |%B|'
|
115
|
-
)
|
116
|
-
Jekyll::Hooks.register :pages, :post_render do |_|
|
117
|
-
progress_bar.increment
|
118
|
-
end
|
119
|
-
|
120
|
-
Jekyll::Hooks.register :documents, :post_render do |_|
|
121
|
-
progress_bar.increment
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
# Public: Filtering a list of items to only keep the one that are
|
126
|
-
# indexable.
|
127
|
-
#
|
128
|
-
# items - List of Pages/Documents
|
129
|
-
#
|
130
|
-
# Note: It also sets the layout to nil, to further speed up the rendering
|
131
|
-
def indexable_list(items)
|
132
|
-
new_list = []
|
133
|
-
items.each do |item|
|
134
|
-
next unless FileBrowser.indexable?(item)
|
135
|
-
|
136
|
-
item.data = {} if item.data.nil?
|
137
|
-
item.data['layout'] = nil
|
138
|
-
new_list << item
|
139
|
-
end
|
140
|
-
new_list
|
141
|
-
end
|
142
|
-
|
143
|
-
# Public: Removing non-indexable Pages, Posts and Documents from the
|
144
|
-
# internals
|
145
|
-
def keep_only_indexable_files
|
146
|
-
@pages = indexable_list(@pages)
|
147
|
-
|
148
|
-
# Applying to each collections
|
149
|
-
@collections.each_value do |collection|
|
150
|
-
collection.docs = indexable_list(collection.docs)
|
151
|
-
end
|
152
|
-
|
153
|
-
# Remove all static files
|
154
|
-
@static_files = []
|
155
|
-
end
|
156
|
-
|
157
|
-
# Public: Extract records from every file and index them
|
158
|
-
def push
|
159
|
-
records = []
|
160
|
-
files = []
|
161
|
-
progress_bar = ProgressBar.create(
|
162
|
-
total: indexable_item_count,
|
163
|
-
format: 'Extracting records (%j%%) |%B|'
|
164
|
-
)
|
165
|
-
each_site_file do |file|
|
166
|
-
# Even if we cleared the list of documents/pages beforehand, some
|
167
|
-
# files might still sneak up to this point (like static files added to
|
168
|
-
# a collection directory), so we check again if they can really be
|
169
|
-
# indexed.
|
170
|
-
next unless FileBrowser.indexable?(file)
|
171
|
-
|
172
|
-
path = FileBrowser.relative_path(file.path)
|
173
|
-
|
174
|
-
Logger.verbose("I:Extracting records from #{path}")
|
175
|
-
file_records = Extractor.run(file)
|
176
|
-
|
177
|
-
files << file
|
178
|
-
records += file_records
|
179
|
-
|
180
|
-
progress_bar.increment
|
181
|
-
end
|
182
|
-
|
183
|
-
# Applying the user hook on the whole list of records
|
184
|
-
records = Hooks.apply_all(records, self)
|
185
|
-
|
186
|
-
# Adding a unique objectID to each record
|
187
|
-
records.map! do |record|
|
188
|
-
Extractor.add_unique_object_id(record)
|
189
|
-
end
|
190
|
-
|
191
|
-
Logger.verbose("I:Found #{files.length} files")
|
192
|
-
|
193
|
-
Indexer.run(records)
|
194
|
-
end
|
195
|
-
end
|
196
70
|
end
|
197
71
|
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Algolia
|
5
|
+
# A Jekyll::Site subclass that overrides process from the parent class to
|
6
|
+
# create JSON records out of rendered documents and push those records to
|
7
|
+
# Algolia instead of writing files to disk.
|
8
|
+
class Site < Jekyll::Site
|
9
|
+
# We expose a way to reset the collection, as it will be needed in the
|
10
|
+
# tests
|
11
|
+
attr_writer :collections
|
12
|
+
|
13
|
+
attr_reader :original_site_files
|
14
|
+
|
15
|
+
# Public: Overwriting the parent method
|
16
|
+
#
|
17
|
+
# This will prepare the website, gathering all files, excluding the one we
|
18
|
+
# don't need to index, then render them (converting to HTML), the finally
|
19
|
+
# calling `push` to push to Algolia
|
20
|
+
def process
|
21
|
+
# Default Jekyll preflight
|
22
|
+
reset
|
23
|
+
read
|
24
|
+
generate
|
25
|
+
|
26
|
+
# Removing all files that won't be indexed, so we don't waste time
|
27
|
+
# rendering them
|
28
|
+
keep_only_indexable_files
|
29
|
+
|
30
|
+
# Starting the rendering progress bar
|
31
|
+
init_rendering_progress_bar
|
32
|
+
|
33
|
+
# Converting them to HTML
|
34
|
+
render
|
35
|
+
|
36
|
+
# Pushing them Algolia
|
37
|
+
push
|
38
|
+
end
|
39
|
+
|
40
|
+
# Public: Return the number of pages/documents to index
|
41
|
+
def indexable_item_count
|
42
|
+
count = @pages.length
|
43
|
+
@collections.each_value { |collection| count += collection.docs.length }
|
44
|
+
count
|
45
|
+
end
|
46
|
+
|
47
|
+
# Public: Init the rendering progress bar, incrementing it for each
|
48
|
+
# rendered item
|
49
|
+
#
|
50
|
+
# This uses Jekyll post_render hooks, listening to both pages and
|
51
|
+
# documents
|
52
|
+
def init_rendering_progress_bar
|
53
|
+
progress_bar = ProgressBar.create(
|
54
|
+
total: indexable_item_count,
|
55
|
+
format: 'Rendering to HTML (%j%%) |%B|'
|
56
|
+
)
|
57
|
+
Jekyll::Hooks.register :pages, :post_render do |_|
|
58
|
+
progress_bar.increment
|
59
|
+
end
|
60
|
+
|
61
|
+
Jekyll::Hooks.register :documents, :post_render do |_|
|
62
|
+
progress_bar.increment
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Public: Filtering a list of items to only keep the one that are
|
67
|
+
# indexable.
|
68
|
+
#
|
69
|
+
# items - List of Pages/Documents
|
70
|
+
#
|
71
|
+
# Note: It also sets the layout to nil, to further speed up the rendering
|
72
|
+
def indexable_list(items)
|
73
|
+
new_list = []
|
74
|
+
items.each do |item|
|
75
|
+
next unless FileBrowser.indexable?(item)
|
76
|
+
|
77
|
+
item.data = {} if item.data.nil?
|
78
|
+
item.data['layout'] = nil
|
79
|
+
new_list << item
|
80
|
+
end
|
81
|
+
new_list
|
82
|
+
end
|
83
|
+
|
84
|
+
# Public: Removing non-indexable Pages, Posts and Documents from the
|
85
|
+
# internals
|
86
|
+
def keep_only_indexable_files
|
87
|
+
@original_site_files = {
|
88
|
+
pages: @pages,
|
89
|
+
collections: @collections,
|
90
|
+
static_files: @static_files
|
91
|
+
}
|
92
|
+
|
93
|
+
@pages = indexable_list(@pages)
|
94
|
+
|
95
|
+
# Applying to each collections
|
96
|
+
@collections.each_value do |collection|
|
97
|
+
collection.docs = indexable_list(collection.docs)
|
98
|
+
end
|
99
|
+
|
100
|
+
# Remove all static files
|
101
|
+
@static_files = []
|
102
|
+
end
|
103
|
+
|
104
|
+
# Public: Extract records from every file and index them
|
105
|
+
def push
|
106
|
+
records = []
|
107
|
+
files = []
|
108
|
+
progress_bar = ProgressBar.create(
|
109
|
+
total: indexable_item_count,
|
110
|
+
format: 'Extracting records (%j%%) |%B|'
|
111
|
+
)
|
112
|
+
each_site_file do |file|
|
113
|
+
# Even if we cleared the list of documents/pages beforehand, some
|
114
|
+
# files might still sneak up to this point (like static files added to
|
115
|
+
# a collection directory), so we check again if they can really be
|
116
|
+
# indexed.
|
117
|
+
next unless FileBrowser.indexable?(file)
|
118
|
+
|
119
|
+
path = FileBrowser.relative_path(file.path)
|
120
|
+
|
121
|
+
Logger.verbose("I:Extracting records from #{path}")
|
122
|
+
file_records = Extractor.run(file)
|
123
|
+
|
124
|
+
files << file
|
125
|
+
records += file_records
|
126
|
+
|
127
|
+
progress_bar.increment
|
128
|
+
end
|
129
|
+
|
130
|
+
# Applying the user hook on the whole list of records
|
131
|
+
records = Hooks.apply_all(records, self)
|
132
|
+
|
133
|
+
# Adding a unique objectID to each record
|
134
|
+
records.map! do |record|
|
135
|
+
Extractor.add_unique_object_id(record)
|
136
|
+
end
|
137
|
+
|
138
|
+
Logger.verbose("I:Found #{files.length} files")
|
139
|
+
|
140
|
+
Indexer.run(records)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
File without changes
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# The default `link` tag allow to link to a specific page, using its relative
|
4
|
+
# path. Because we might not be indexing the destination of the link, we might
|
5
|
+
# not have the representation of the page in our data. If that happens, the
|
6
|
+
# `link` tag fails.
|
7
|
+
#
|
8
|
+
# To fix that we'll overwrite the default `link` tag to loop over a backup copy
|
9
|
+
# of the original files (before we clean it for indexing)
|
10
|
+
#
|
11
|
+
# https://github.com/algolia/jekyll-algolia/issues/62
|
12
|
+
class JekyllAlgoliaLink < Jekyll::Tags::Link
|
13
|
+
def render(context)
|
14
|
+
original_files = context.registers[:site].original_site_files
|
15
|
+
|
16
|
+
original_files[:pages].each do |page|
|
17
|
+
return page.url if page.relative_path == @relative_path
|
18
|
+
end
|
19
|
+
|
20
|
+
original_files[:collections].each_value do |collection|
|
21
|
+
collection.docs.each do |item|
|
22
|
+
return item.url if item.relative_path == @relative_path
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
original_files[:static_files].each do |asset|
|
27
|
+
return asset.url if asset.relative_path == @relative_path
|
28
|
+
return asset.url if asset.relative_path == "/#{@relative_path}"
|
29
|
+
end
|
30
|
+
|
31
|
+
'/'
|
32
|
+
end
|
33
|
+
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
|
+
version: 1.3.2
|
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-
|
11
|
+
date: 2018-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: algolia_html_extractor
|
@@ -303,7 +303,9 @@ files:
|
|
303
303
|
- lib/jekyll/algolia/hooks.rb
|
304
304
|
- lib/jekyll/algolia/indexer.rb
|
305
305
|
- lib/jekyll/algolia/logger.rb
|
306
|
-
- lib/jekyll/algolia/overwrites.rb
|
306
|
+
- lib/jekyll/algolia/overwrites/jekyll-algolia-site.rb
|
307
|
+
- lib/jekyll/algolia/overwrites/jekyll-document.rb
|
308
|
+
- lib/jekyll/algolia/overwrites/jekyll-tags-link.rb
|
307
309
|
- lib/jekyll/algolia/progress_bar.rb
|
308
310
|
- lib/jekyll/algolia/utils.rb
|
309
311
|
- lib/jekyll/algolia/version.rb
|