From 2cdaaa89cf957e098b3c670cc2793b1c7c03158f Mon Sep 17 00:00:00 2001 From: Dru Sellers Date: Mon, 5 Jun 2017 14:20:59 -0500 Subject: [PATCH] Index collections as well as posts --- lib/searchyll.rb | 30 +++++++++++++++++++++++------- lib/searchyll/indexer.rb | 2 +- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/lib/searchyll.rb b/lib/searchyll.rb index e0fa25a..572819d 100644 --- a/lib/searchyll.rb +++ b/lib/searchyll.rb @@ -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 diff --git a/lib/searchyll/indexer.rb b/lib/searchyll/indexer.rb index c36aaf6..ba929fe 100644 --- a/lib/searchyll/indexer.rb +++ b/lib/searchyll/indexer.rb @@ -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|