Class: Jekyll::OldComments

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/jekyll-oldcomments.rb

Instance Method Summary collapse

Instance Method Details

#render(context) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/jekyll-oldcomments.rb', line 5

def render(context)
  comment_dir = File.join(context.registers[:site].source, '_comments','*.md')
  @comment_map = Hash.new
  Dir[comment_dir].each do |comment|
    yaml = YAML.load_file(comment)
    fd = File.open(comment,'r')
    text = fd.read().split('---')[2]
    fd.close
    path = yaml['path'].strip
    if not @comment_map.has_key?(path)
      @comment_map[path] = Array.new
    end
    @comment_map[path] << { 'meta' => yaml, 'text' => text.gsub(/^(.*)$/, '<p>\1</p>') }
  end

  @comment_map.each do |key, value|
    @comment_map[key].sort!{ |a,b| a['meta']['date']<=>b['meta']['date'] } 
  end

  tmpl = File.read File.join Dir.pwd, "_includes", 'comments.html'
  (Liquid::Template.parse tmpl).render('comments' => @comment_map[context.registers[:page]['permalink']])
end