Skip to content

Commit 06f390c

Browse files
committed
plugins/algolia: fix community resources index generator
Signed-off-by: Ruby Iris Juric <[email protected]>
1 parent 2b3c824 commit 06f390c

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

plugins/generator_algolia.rb

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -134,26 +134,28 @@ def generate_documentation
134134
end
135135

136136
def generate_community_resources
137-
resources = %w(community_tools community_apps community_libraries)
138-
documents = []
139-
resources.each do | type |
140-
return nil if @site.collections[type].nil?
141-
142-
@site.collections[type].docs.each do | resource |
143-
document = {
144-
'objectID' => resource.url,
145-
'title' => resource.data['name'],
146-
'url' => resource.url,
147-
'content' => HTMLEntities.new.decode(resource.get_output),
148-
'resourceType' => type,
149-
'type' => 'community resource',
150-
'randomCode' => @random_code
151-
}
152-
documents << document
137+
resources = %w[community_tools community_apps community_libraries]
138+
139+
resources.flat_map do |type|
140+
collection = @site.collections[type]
141+
return [] if collection.nil?
142+
143+
collection.docs.map do |resource|
144+
Algolia::Search::MultipleBatchRequest.new(
145+
action: 'addObject',
146+
index_name: "#{@prefix}community-resources",
147+
body: {
148+
'objectID' => resource.url,
149+
'title' => resource.data['name'],
150+
'url' => resource.url,
151+
'content' => HTMLEntities.new.decode(resource.get_output),
152+
'resourceType' => type,
153+
'type' => 'community resource',
154+
'randomCode' => @random_code
155+
}
156+
)
153157
end
154158
end
155-
156-
@indexes['community-resources'].save_objects(documents)
157159
end
158160

159161
def generate_blog_posts

0 commit comments

Comments
 (0)