Skip to content

Commit

Permalink
add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nz committed Apr 26, 2016
1 parent afa05a7 commit 0be5381
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions lib/searchyou/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,43 @@ class Generator < Jekyll::Generator
safe true
priority :lowest

def self.abort(msg)
$stderr.puts(msg)
end
# Public: Invoked by Jekyll during the generation phase.
def generate(site)

def self.elasticsearch_url(site)
ENV['ELASTICSEARCH_URL'] ||
ENV['BONSAI_URL'] ||
((site.config||{})['elasticsearch']||{})['url'] ||
raise(ArgumentError, "No Elasticsearch URL present, skipping indexing")
end
# Find the ES URL
url = elasticsearch_url(site)

def generate(site)
url = self.class.elasticsearch_url(site)
# Prepare the indexer
indexer = Searchyou::Indexer.new(site)
indexer.start

# Iterate through the site contents and send to indexer
# TODO: what are we indexing?
site.posts.docs.each do |doc|
indexer << doc.data.merge({
id: doc.basename_without_ext,
content: doc.content
})
end

# Signal to the indexer that we're done adding content
indexer.finish


# Handle any exceptions gracefully
rescue => e
$stderr.puts "Searchyll: #{e.class.name} - #{e.message}"
end

# Figure out the Elasticsearch URL, from an environment variable or the
# Jekyll site configuration. Raises an exception if none is found, so we
# can skip the indexing.
def elasticsearch_url(site)
ENV['BONSAI_URL'] || ENV['ELASTICSEARCH_URL'] ||
((site.config||{})['elasticsearch']||{})['url'] ||
raise(ArgumentError, "No Elasticsearch URL present, skipping indexing")
end

end

end

0 comments on commit 0be5381

Please sign in to comment.