Module: Jekyll::Enki

Defined in:
lib/jekyll/migrators/enki.rb

Constant Summary collapse

SQL =
"  SELECT p.id,\n         p.title,\n         p.slug,\n         p.body,\n         p.published_at as date,\n         p.cached_tag_list as tags\n  FROM posts p\n"

Class Method Summary collapse

Class Method Details

.process(dbname, user, pass, host = 'localhost') ⇒ Object

Just working with postgres, but can be easily adapted to work with both mysql and postgres.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/jekyll/migrators/enki.rb', line 22

def self.process(dbname, user, pass, host = 'localhost')
  FileUtils.mkdir_p('_posts')
  db = Sequel.postgres(:database => dbname,
                       :user => user,
                       :password => pass,
                       :host => host,
                       :encoding => 'utf8')

  db[SQL].each do |post|
    name = [ sprintf("%.04d", post[:date].year),
             sprintf("%.02d", post[:date].month),
             sprintf("%.02d", post[:date].day),
             post[:slug].strip ].join('-')
    name += '.textile'

    File.open("_posts/#{name}", 'w') do |f|
      f.puts({ 'layout'   => 'post',
               'title'    => post[:title].to_s,
               'enki_id'  => post[:id],
               'categories'  => post[:tags]
             }.delete_if { |k, v| v.nil? || v == '' }.to_yaml)
      f.puts '---'
      f.puts post[:body].delete("\r")
    end
  end
end