diff --git a/README.textile b/README.textile index e50f0524..a88977e9 100644 --- a/README.textile +++ b/README.textile @@ -379,6 +379,25 @@ You may need to adjust the SQL query used to retrieve MT entries. Left alone, it will attempt to pull all entries across all blogs regardless of status. Please check the results and verify the posts before publishing. +h3. Typo 4+ + +To migrate your Typo blog into Jekyll, you'll need read access to the MySQL +database. The lib/jekyll/converters/typo.rb module provides a simple convert +to create .html, .textile, or .markdown files in a _posts directory based on +the entries contained therein. + + $ export DB=my_typo_db + $ export USER=dbuser + $ export PASS=dbpass + $ ruby -r './lib/jekyll/converters/typo' -e 'Jekyll::Typo.process( \ + "#{ENV["DB"]}", "#{ENV["USER"]}", "#{ENV["PASS"]}")' + +You may need to adjust the code used to filter Typo entries. Left alone, +it will attempt to pull all entries across all blogs that were published. +This code also has only been tested with Typo version 4+. Previous versions +of Typo may not convert correctly. Please check the results and verify the +posts before publishing. + h2. License (The MIT License) diff --git a/lib/jekyll/converters/typo.rb b/lib/jekyll/converters/typo.rb new file mode 100644 index 00000000..febac65d --- /dev/null +++ b/lib/jekyll/converters/typo.rb @@ -0,0 +1,49 @@ +# Author: Toby DiPasquale +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