Skip to content

Commit

Permalink
Index collections as well as posts
Browse files Browse the repository at this point in the history
  • Loading branch information
drusellers committed Jun 5, 2017
1 parent ee7e309 commit 2cdaaa8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
30 changes: 23 additions & 7 deletions lib/searchyll.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,32 @@
indexers[site].finish
end

Jekyll::Hooks.register :posts, :post_render do |post|
# gets random pages like your home page
Jekyll::Hooks.register :pages, :post_render do |page|
# strip html
nokogiri_doc = Nokogiri::HTML(post.output)
nokogiri_doc = Nokogiri::HTML(page.output)

puts %(indexing #{post.url})
puts %( indexing page #{page.url})

indexer = indexers[post.site]
indexer << post.data.merge({
id: post.id,
url: post.url,
indexer = indexers[page.site]
indexer << page.data.merge({
id: page.name,
url: page.url,
text: nokogiri_doc.xpath("//article//text()").to_s.gsub(/\s+/, " ")
})
end

# gets both posts and collections
Jekyll::Hooks.register :documents, :post_render do |document|
# strip html
nokogiri_doc = Nokogiri::HTML(document.output)

puts %( indexing document #{document.url})

indexer = indexers[document.site]
indexer << document.data.merge({
id: document.id,
url: document.url,
text: nokogiri_doc.xpath("//article//text()").to_s.gsub(/\s+/, " ")
})
end
Expand Down
2 changes: 1 addition & 1 deletion lib/searchyll/indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def finalize!

# delete old indices
cleanup_indices = http_delete("/#{old_indices.join(',')}")
print %(Old indices: #{old_indices})
puts %( Old indices: #{old_indices.join(', ')})

# run the prepared requests
http_start do |http|
Expand Down

0 comments on commit 2cdaaa8

Please sign in to comment.