Sha256: 0b590a58554dd63d2afab077e374effc88bbc177e9a9e0fa6537ec7c5b75e2d9

Contents?: true

Size: 1.56 KB

Versions: 69

Compression:

Stored size: 1.56 KB

Contents

# Author: Toby DiPasquale <toby@cbcg.net>
require 'fileutils'
require 'rubygems'
require 'sequel'

module Jekyll
  module Typo
    # this SQL *should* work for both MySQL and PostgreSQL, but I haven't
    # tested PostgreSQL yet (as of 2008-12-16)
    SQL = <<-EOS
    SELECT c.id id,
           c.title title,
           c.permalink slug,
           c.body body,
           c.published_at date,
           c.state state,
           COALESCE(tf.name, 'html') filter
      FROM contents c
           LEFT OUTER JOIN text_filters tf
                        ON c.text_filter_id = tf.id
    EOS

    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

  end   # module Typo
end   # module Jekyll

Version data entries

69 entries across 69 versions & 27 rubygems

Version Path
Chrononaut-hyde-0.1.0 lib/jekyll/converters/typo.rb
Chrononaut-hyde-0.1.1 lib/jekyll/converters/typo.rb
PerfectlyNormal-jekyll-0.5.1 lib/jekyll/converters/typo.rb
PerfectlyNormal-jekyll-0.5.3 lib/jekyll/converters/typo.rb
cduruk-jekyll-0.5.2 lib/jekyll/converters/typo.rb
codeslinger-jekyll-0.5.0 lib/jekyll/converters/typo.rb
codeslinger-jekyll-0.5.1 lib/jekyll/converters/typo.rb
codeslinger-jekyll-0.5.2 lib/jekyll/converters/typo.rb
codeslinger-jekyll-0.5.3 lib/jekyll/converters/typo.rb
codeslinger-jekyll-0.5.4 lib/jekyll/converters/typo.rb
cypher-jekyll-0.5.2 lib/jekyll/converters/typo.rb
cypher-jekyll-0.5.3 lib/jekyll/converters/typo.rb
henrik-jekyll-0.5.0 lib/jekyll/converters/typo.rb
henrik-jekyll-0.5.1 lib/jekyll/converters/typo.rb
henrik-jekyll-0.5.2 lib/jekyll/converters/typo.rb
jroes-jekyll-0.5.1 lib/jekyll/converters/typo.rb
jroes-jekyll-0.5.2 lib/jekyll/converters/typo.rb
jroes-jekyll-0.5.3 lib/jekyll/converters/typo.rb
jroes-jekyll-0.5.4 lib/jekyll/converters/typo.rb
matflores-jekyll-0.5.0 lib/jekyll/converters/typo.rb