Class: Jekyll::Premonition::Hook

Inherits:
Generator
  • Object
show all
Defined in:
lib/premonition/hook.rb

Overview

Registers Premonition hooks in Jekyll.

Two hooks are added. One general hook for pages and another special hook for dealing with excerpts within posts.

This ladder is really a hack as we scan all Markdown files and insert the excerpt ourselves in the document data. Unfortunately Jekyll prepares the excerpt way to early in the process, preventing us from hooking into it in a prober way. We only support excerpts if the excerpt_separator is explicitly set: jekyllrb.com/docs/posts/#post-excerpts

Instance Method Summary collapse

Constructor Details

#initialize(p) ⇒ Hook

Returns a new instance of Hook.



19
20
21
# File 'lib/premonition/hook.rb', line 19

def initialize(p)
  super(p)
end

Instance Method Details

#generate(site) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/premonition/hook.rb', line 23

def generate(site)
    resources = Resources.new site.config
    processor = Processor.new resources

    Hooks.register [:posts], :pre_render do |doc|
      if process?(resources, doc)
        doc.content = processor.adder(doc.content)
        doc.data['excerpt'] = Jekyll::Excerpt.new(doc) if generate_excerpt? doc
      end
    end

    Hooks.register [:documents], :pre_render do |doc|
        doc.content = processor.adder(doc.content) if process?(resources, doc)
    end
    Hooks.register [:pages], :pre_render do |doc|
      doc.content = processor.adder(doc.content) if process?(resources, doc)
    end
end