Module: Jekyll::Typo
- Defined in:
- lib/jekyll/converters/typo.rb
Constant Summary collapse
- SQL =
this SQL should work for both MySQL and PostgreSQL, but I haven’t tested PostgreSQL yet (as of 2008-12-16)
"SELECT c.id id,\nc.title title,\nc.permalink slug,\nc.body body,\nc.published_at date,\nc.state state,\nCOALESCE(tf.name, 'html') filter\nFROM contents c\nLEFT OUTER JOIN text_filters tf\nON c.text_filter_id = tf.id\n"
Class Method Summary collapse
Class Method Details
.process(dbname, user, pass, host = 'localhost') ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/jekyll/converters/typo.rb', line 23 def self.process dbname, user, pass, host='localhost' FileUtils.mkdir_p '_posts' db = Sequel.mysql dbname, :user => user, :password => pass, :host => host db[SQL].each do |post| next unless post[:state] =~ /Published/ name = [ sprintf("%.04d", post[:date].year), sprintf("%.02d", post[:date].month), sprintf("%.02d", post[:date].day), post[:slug].strip ].join('-') # Can have more than one text filter in this field, but we just want # the first one for this name += '.' + post[:filter].split(' ')[0] File.open("_posts/#{name}", 'w') do |f| f.puts({ 'layout' => 'post', 'title' => post[:title].to_s, 'typo_id' => post[:id] }.delete_if { |k, v| v.nil? || v == '' }.to_yaml) f.puts '---' f.puts post[:body].delete("\r") end end end |