From adf9ca5a05371454bcf5e79cc20dc843c2434eb9 Mon Sep 17 00:00:00 2001 From: Scott Hill Date: Thu, 5 Aug 2010 15:36:14 -0700 Subject: [PATCH 1/4] Added code to change the extension of a post based on the format used to write the post in MT. --- lib/jekyll/migrators/mt.rb | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/migrators/mt.rb b/lib/jekyll/migrators/mt.rb index 27b12226..91d55c38 100644 --- a/lib/jekyll/migrators/mt.rb +++ b/lib/jekyll/migrators/mt.rb @@ -5,6 +5,7 @@ require 'rubygems' require 'sequel' require 'fileutils' +require 'yaml' # NOTE: This converter requires Sequel and the MySQL gems. # The MySQL gem can be difficult to install on OS X. Once you have MySQL @@ -17,7 +18,7 @@ module Jekyll # This query will pull blog posts from all entries across all blogs. If # you've got unpublished, deleted or otherwise hidden posts please sift # through the created posts to make sure nothing is accidently published. - QUERY = "SELECT entry_id, entry_basename, entry_text, entry_text_more, entry_created_on, entry_title FROM mt_entry" + QUERY = "SELECT entry_id, entry_basename, entry_text, entry_text_more, entry_created_on, entry_title, entry_convert_breaks FROM mt_entry" def self.process(dbname, user, pass, host = 'localhost') db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host) @@ -30,6 +31,7 @@ module Jekyll date = post[:entry_created_on] content = post[:entry_text] more_content = post[:entry_text_more] + entry_convert_breaks = post[:entry_convert_breaks] # Be sure to include the body and extended body. if more_content != nil @@ -39,7 +41,7 @@ module Jekyll # Ideally, this script would determine the post format (markdown, html # , etc) and create files with proper extensions. At this point it # just assumes that markdown will be acceptable. - name = [date.year, date.month, date.day, slug].join('-') + ".markdown" + name = [date.year, date.month, date.day, slug].join('-') + '.' + self.suffix(entry_convert_breaks) data = { 'layout' => 'post', @@ -55,5 +57,21 @@ module Jekyll end end + + def self.suffix(entry_type) + if entry_type.nil? || entry_type.include?("markdown") + # The markdown plugin I have saves this as "markdown_with_smarty_pants", so I just look for "markdown". + "markdown" + elsif entry_type.include?("textile") + # This is saved as "textile_2" on my installation of MT 5.1. + "textile" + elsif entry_type == "0" || entry_type.include?("richtext") + # richtext looks to me like it's saved as HTML, so I include it here. + "html" + else + # Other values might need custom work. + entry_type + end + end end end From f6acbb869e12fdc28da812185f35d81ed77a81b9 Mon Sep 17 00:00:00 2001 From: Scott Hill Date: Fri, 6 Aug 2010 01:26:32 -0700 Subject: [PATCH 2/4] Changed the date used by Jekyll to be the date the post was authored on instead of the date it was created. If the latter is used on an imported post, it gets the import date instead of the date the post was originally written. --- lib/jekyll/migrators/mt.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/migrators/mt.rb b/lib/jekyll/migrators/mt.rb index 91d55c38..c25ee2ff 100644 --- a/lib/jekyll/migrators/mt.rb +++ b/lib/jekyll/migrators/mt.rb @@ -18,7 +18,7 @@ module Jekyll # This query will pull blog posts from all entries across all blogs. If # you've got unpublished, deleted or otherwise hidden posts please sift # through the created posts to make sure nothing is accidently published. - QUERY = "SELECT entry_id, entry_basename, entry_text, entry_text_more, entry_created_on, entry_title, entry_convert_breaks FROM mt_entry" + QUERY = "SELECT entry_id, entry_basename, entry_text, entry_text_more, entry_authored_on, entry_title, entry_convert_breaks FROM mt_entry" def self.process(dbname, user, pass, host = 'localhost') db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host) @@ -28,7 +28,7 @@ module Jekyll db[QUERY].each do |post| title = post[:entry_title] slug = post[:entry_basename] - date = post[:entry_created_on] + date = post[:entry_authored_on] content = post[:entry_text] more_content = post[:entry_text_more] entry_convert_breaks = post[:entry_convert_breaks] From b3cec398431c379eebd09679c7ac77766d997aab Mon Sep 17 00:00:00 2001 From: Scott Hill Date: Fri, 6 Aug 2010 10:33:59 -0700 Subject: [PATCH 3/4] Now adding a "date" to the YAML front-matter of a post, based on the original date the post was authored according to MT. --- lib/jekyll/migrators/mt.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/jekyll/migrators/mt.rb b/lib/jekyll/migrators/mt.rb index c25ee2ff..414c6366 100644 --- a/lib/jekyll/migrators/mt.rb +++ b/lib/jekyll/migrators/mt.rb @@ -47,6 +47,7 @@ module Jekyll 'layout' => 'post', 'title' => title.to_s, 'mt_id' => post[:entry_id], + 'date' => date }.delete_if { |k,v| v.nil? || v == ''}.to_yaml File.open("_posts/#{name}", "w") do |f| From a556e4f29e898c099894f1e118294498fb74ca59 Mon Sep 17 00:00:00 2001 From: Scott Hill Date: Sun, 8 Aug 2010 22:59:38 -0700 Subject: [PATCH 4/4] Swapping a '-' for the word separator for imported entries since that's the MT style, and I don't want to break existing permalinks. --- lib/jekyll/migrators/mt.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/migrators/mt.rb b/lib/jekyll/migrators/mt.rb index 414c6366..88cdb1a4 100644 --- a/lib/jekyll/migrators/mt.rb +++ b/lib/jekyll/migrators/mt.rb @@ -27,7 +27,7 @@ module Jekyll db[QUERY].each do |post| title = post[:entry_title] - slug = post[:entry_basename] + slug = post[:entry_basename].gsub(/_/, '-') date = post[:entry_authored_on] content = post[:entry_text] more_content = post[:entry_text_more]