Class: Searchyll::Generator

Inherits:
Jekyll::Generator
  • Object
show all
Defined in:
lib/searchyll/generator.rb

Instance Method Summary collapse

Instance Method Details

#generate(site) ⇒ Object

Public: Invoked by Jekyll during the generation phase.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/searchyll/generator.rb', line 12

def generate(site)

  # Gather the configuration options
  configuration = Configuration.new(site)

  # Prepare the indexer
  indexer = Searchyll::Indexer.new(configuration)
  indexer.start

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

  Jekyll::Hooks.register :posts, :post_render do |post|
    puts post.output
  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}"
  $stderr.puts "Backtrace: #{e.backtrace.each{|l| puts l};nil}"
  raise(e)
end