Skip to content

Commit b5a112c

Browse files
committed
Merge pull request #224 from markstos/add-mt-postgresql-support
Merge pull request 224
2 parents 0dbf5b1 + 76f0924 commit b5a112c

File tree

2 files changed

+27
-2
lines changed
  • lib/jekyll-import/importers
  • site/_importers

2 files changed

+27
-2
lines changed

lib/jekyll-import/importers/mt.rb

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,17 @@ def self.require_deps
2626
end
2727

2828
def self.specify_options(c)
29+
c.option 'engine', "--engine ENGINE", "Database engine, (default: 'mysql', postgres also supported)"
2930
c.option 'dbname', '--dbname DB', 'Database name'
3031
c.option 'user', '--user USER', 'Database user name'
3132
c.option 'password', '--password PW', "Database user's password, (default: '')"
3233
c.option 'host', '--host HOST', 'Database host name (default: "localhost")'
34+
c.option 'port', '--port PORT', 'Custom database port connect to (optional)'
35+
c.option 'blog_id', '--blog_id ID', 'Specify a single Movable Type blog ID to import (default: all blogs)'
36+
c.option 'categories', '--categories', "If true, save post's categories in its YAML front matter. (default: true)"
37+
c.option 'src_encoding', '--src_encoding ENCODING', "Encoding of strings from database. (default: UTF-8)"
38+
c.option 'dest_encoding', '--dest_encoding ENCODING', "Encoding of output strings. (default: UTF-8)"
39+
c.option 'comments','--comments', "If true, output comments in _comments directory (default: false)"
3340
end
3441

3542
# By default this migrator will include posts for all your MovableType blogs.
@@ -58,6 +65,7 @@ def self.specify_options(c)
5865
def self.process(options)
5966
options = default_options.merge(options)
6067

68+
engine = options.fetch('engine', 'mysql')
6169
dbname = options.fetch('dbname')
6270
user = options.fetch('user')
6371
pass = options.fetch('password', "")
@@ -66,7 +74,19 @@ def self.process(options)
6674

6775
posts_name_by_id = { } if comments
6876

69-
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host)
77+
db_opts = { user => user, :password => pass, :host => host }
78+
79+
# Use the default port by default, but set the port if one is provided.
80+
if options['port']
81+
db_opts[:port] = options['port']
82+
end
83+
84+
if engine != 'mysql' && engine != 'postgres'
85+
abort("unsupported --engine value supplied '#{engine}'. Only 'mysql' and 'postgres' are supported")
86+
end
87+
88+
db = Sequel.public_send(engine, dbname, db_opts)
89+
7090
post_categories = db[:mt_placement].join(:mt_category, :category_id => :placement_category_id)
7191

7292
FileUtils.mkdir_p "_posts"

site/_importers/mt.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@ To import your posts from [Movable Type](http://movabletype.org), run:
1212
{% highlight bash %}
1313
$ ruby -rubygems -e 'require "jekyll-import";
1414
JekyllImport::Importers::MT.run({
15+
"engine" => "mysql", # "postgres" is also supported
1516
"dbname" => "name",
1617
"user" => "myuser",
1718
"password" => "mypassword",
1819
"host" => "myhost",
19-
"comments" => true
20+
"blog_id" => nil, # Set to specific ID to iimport just one blog
21+
"categories" => true, # Set to false to not save categories to front matter
22+
"src_encoding" => "UTF-8",
23+
"dest_encoding" => "UTF-8",
24+
"comments" => true
2025
})'
2126
{% endhighlight %}
2227

0 commit comments

Comments
 (0)