Skip to content

Commit 2cdaaa8

Browse files
committed
Index collections as well as posts
1 parent ee7e309 commit 2cdaaa8

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

lib/searchyll.rb

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,32 @@
1919
indexers[site].finish
2020
end
2121

22-
Jekyll::Hooks.register :posts, :post_render do |post|
22+
# gets random pages like your home page
23+
Jekyll::Hooks.register :pages, :post_render do |page|
2324
# strip html
24-
nokogiri_doc = Nokogiri::HTML(post.output)
25+
nokogiri_doc = Nokogiri::HTML(page.output)
2526

26-
puts %(indexing #{post.url})
27+
puts %( indexing page #{page.url})
2728

28-
indexer = indexers[post.site]
29-
indexer << post.data.merge({
30-
id: post.id,
31-
url: post.url,
29+
indexer = indexers[page.site]
30+
indexer << page.data.merge({
31+
id: page.name,
32+
url: page.url,
33+
text: nokogiri_doc.xpath("//article//text()").to_s.gsub(/\s+/, " ")
34+
})
35+
end
36+
37+
# gets both posts and collections
38+
Jekyll::Hooks.register :documents, :post_render do |document|
39+
# strip html
40+
nokogiri_doc = Nokogiri::HTML(document.output)
41+
42+
puts %( indexing document #{document.url})
43+
44+
indexer = indexers[document.site]
45+
indexer << document.data.merge({
46+
id: document.id,
47+
url: document.url,
3248
text: nokogiri_doc.xpath("//article//text()").to_s.gsub(/\s+/, " ")
3349
})
3450
end

lib/searchyll/indexer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def finalize!
162162

163163
# delete old indices
164164
cleanup_indices = http_delete("/#{old_indices.join(',')}")
165-
print %(Old indices: #{old_indices})
165+
puts %( Old indices: #{old_indices.join(', ')})
166166

167167
# run the prepared requests
168168
http_start do |http|

0 commit comments

Comments
 (0)