Skip to content

Commit

Permalink
Merge remote branch 'stmpjmpr/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mojombo committed Nov 20, 2010
2 parents e2d26ff + 0014690 commit 53b9994
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Add --limit-posts cli option (#212)
* Add uri_escape filter (#234)
* Add --base-url cli option (#235)
* Improve MT migrator (#238)
* Bug Fixes
* Fixed filename basename generation (#208)
* Set mode to UTF8 on Sequel connections (#237)
Expand Down
26 changes: 22 additions & 4 deletions lib/jekyll/migrators/mt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,7 +18,7 @@ module MT
# 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_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, :encoding => 'utf8')
Expand All @@ -26,10 +27,11 @@ def self.process(dbname, user, pass, host = 'localhost')

db[QUERY].each do |post|
title = post[:entry_title]
slug = post[:entry_basename]
date = post[:entry_created_on]
slug = post[:entry_basename].gsub(/_/, '-')
date = post[:entry_authored_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
Expand All @@ -39,12 +41,13 @@ def self.process(dbname, user, pass, host = 'localhost')
# 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',
'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|
Expand All @@ -53,7 +56,22 @@ def self.process(dbname, user, pass, host = 'localhost')
f.puts content
end
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

0 comments on commit 53b9994

Please sign in to comment.