Adding Movable Type migration library to lib/jekyll/converters/.
This commit is contained in:
parent
a8ab6a0adb
commit
8477cb5946
|
@ -8,6 +8,8 @@ lib/jekyll.rb
|
||||||
lib/jekyll/albino.rb
|
lib/jekyll/albino.rb
|
||||||
lib/jekyll/converters/csv.rb
|
lib/jekyll/converters/csv.rb
|
||||||
lib/jekyll/converters/mephisto.rb
|
lib/jekyll/converters/mephisto.rb
|
||||||
|
lib/jekyll/converters/wordpress.rb
|
||||||
|
lib/jekyll/converters/mt.rb
|
||||||
lib/jekyll/convertible.rb
|
lib/jekyll/convertible.rb
|
||||||
lib/jekyll/filters.rb
|
lib/jekyll/filters.rb
|
||||||
lib/jekyll/layout.rb
|
lib/jekyll/layout.rb
|
||||||
|
|
|
@ -361,6 +361,24 @@ The best way to get your changes merged back into core is as follows:
|
||||||
# Push the branch up to GitHub
|
# Push the branch up to GitHub
|
||||||
# Send me (mojombo) a pull request for your branch
|
# Send me (mojombo) a pull request for your branch
|
||||||
|
|
||||||
|
h2. Blog migrations
|
||||||
|
|
||||||
|
h3. Movable Type
|
||||||
|
|
||||||
|
To migrate your MT blog into Jekyll, you'll need read access to the database.
|
||||||
|
The lib/jekyll/converters/mt.rb module provides a simple convert to create
|
||||||
|
.markdown files in a _posts directory based on the entries contained therein.
|
||||||
|
|
||||||
|
$ export DB=my_mtdb
|
||||||
|
$ export USER=dbuser
|
||||||
|
$ export PASS=dbpass
|
||||||
|
$ ruby -r './lib/jekyll/converters/mt' -e 'Jekyll::MT.process( \
|
||||||
|
"#{ENV["DB"]}", "#{ENV["USER"]}", "#{ENV["PASS"]}")'
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
h2. License
|
h2. License
|
||||||
|
|
||||||
(The MIT License)
|
(The MIT License)
|
||||||
|
|
3
Rakefile
3
Rakefile
|
@ -18,4 +18,7 @@ namespace :convert do
|
||||||
task :mephisto do
|
task :mephisto do
|
||||||
sh %q(ruby -r './lib/jekyll/converters/mephisto' -e 'Jekyll::Mephisto.postgres(:database => "#{ENV["DB"]}")')
|
sh %q(ruby -r './lib/jekyll/converters/mephisto' -e 'Jekyll::Mephisto.postgres(:database => "#{ENV["DB"]}")')
|
||||||
end
|
end
|
||||||
|
task :mt do
|
||||||
|
sh %q(ruby -r './lib/jekyll/converters/mt' -e 'Jekyll::MT.process("#{ENV["DB"]}", "#{ENV["USER"]}", "#{ENV["PASS"]}")')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
# Created by Nick Gerakines, open source and publically available under the
|
||||||
|
# MIT license. Use this module at your own risk.
|
||||||
|
# I'm an Erlang/Perl/C++ guy so please forgive my dirty ruby.
|
||||||
|
|
||||||
|
require 'rubygems'
|
||||||
|
require 'sequel'
|
||||||
|
require 'fileutils'
|
||||||
|
|
||||||
|
# NOTE: This converter requires Sequel and the MySQL gems.
|
||||||
|
# The MySQL gem can be difficult to install on OS X. Once you have MySQL
|
||||||
|
# installed, running the following commands should work:
|
||||||
|
# $ sudo gem install sequel
|
||||||
|
# $ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
|
||||||
|
|
||||||
|
module Jekyll
|
||||||
|
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"
|
||||||
|
|
||||||
|
def self.process(dbname, user, pass, host = 'localhost')
|
||||||
|
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host)
|
||||||
|
|
||||||
|
FileUtils.mkdir_p "_posts"
|
||||||
|
|
||||||
|
db[QUERY].each do |post|
|
||||||
|
title = post[:entry_title]
|
||||||
|
slug = post[:entry_basename]
|
||||||
|
date = post[:entry_created_on]
|
||||||
|
content = post[:entry_text]
|
||||||
|
more_content = post[:entry_text_more]
|
||||||
|
|
||||||
|
# Be sure to include the body and extended body.
|
||||||
|
if more_content != nil
|
||||||
|
conent = content + " \n" + more_content
|
||||||
|
end
|
||||||
|
|
||||||
|
# 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"
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'layout' => 'post',
|
||||||
|
'title' => title.to_s,
|
||||||
|
'mt_id' => post[:entry_id],
|
||||||
|
}.delete_if { |k,v| v.nil? || v == ''}.to_yaml
|
||||||
|
|
||||||
|
File.open("_posts/#{name}", "w") do |f|
|
||||||
|
f.puts data
|
||||||
|
f.puts "---"
|
||||||
|
f.puts content
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue