jekyll-import 0.1.0.beta3 → 0.1.0.beta4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +6 -14
- data/History.markdown +18 -0
- data/README.markdown +12 -1
- data/jekyll-import.gemspec +31 -25
- data/lib/jekyll-import.rb +50 -1
- data/lib/jekyll-import/importer.rb +11 -0
- data/lib/jekyll-import/importers.rb +10 -0
- data/lib/jekyll-import/importers/csv.rb +50 -0
- data/lib/jekyll-import/importers/drupal6.rb +139 -0
- data/lib/jekyll-import/importers/drupal7.rb +102 -0
- data/lib/jekyll-import/importers/enki.rb +76 -0
- data/lib/jekyll-import/importers/google_reader.rb +68 -0
- data/lib/jekyll-import/importers/joomla.rb +83 -0
- data/lib/jekyll-import/importers/jrnl.rb +127 -0
- data/lib/jekyll-import/importers/marley.rb +72 -0
- data/lib/jekyll-import/importers/mephisto.rb +109 -0
- data/lib/jekyll-import/importers/mt.rb +169 -0
- data/lib/jekyll-import/importers/posterous.rb +139 -0
- data/lib/jekyll-import/importers/rss.rb +71 -0
- data/lib/jekyll-import/importers/s9y.rb +67 -0
- data/lib/jekyll-import/importers/textpattern.rb +76 -0
- data/lib/jekyll-import/importers/tumblr.rb +265 -0
- data/lib/jekyll-import/importers/typo.rb +89 -0
- data/lib/jekyll-import/importers/wordpress.rb +323 -0
- data/lib/jekyll-import/importers/wordpressdotcom.rb +97 -0
- data/lib/jekyll/commands/import.rb +1 -0
- data/test/helper.rb +3 -1
- data/test/test_jrnl_importer.rb +39 -0
- data/test/test_mt_importer.rb +16 -16
- data/test/test_tumblr_importer.rb +61 -0
- data/test/test_wordpress_importer.rb +1 -1
- data/test/test_wordpressdotcom_importer.rb +1 -1
- metadata +53 -32
- data/lib/jekyll/jekyll-import/csv.rb +0 -30
- data/lib/jekyll/jekyll-import/drupal6.rb +0 -112
- data/lib/jekyll/jekyll-import/drupal7.rb +0 -74
- data/lib/jekyll/jekyll-import/enki.rb +0 -49
- data/lib/jekyll/jekyll-import/google_reader.rb +0 -61
- data/lib/jekyll/jekyll-import/joomla.rb +0 -53
- data/lib/jekyll/jekyll-import/marley.rb +0 -52
- data/lib/jekyll/jekyll-import/mephisto.rb +0 -84
- data/lib/jekyll/jekyll-import/mt.rb +0 -142
- data/lib/jekyll/jekyll-import/posterous.rb +0 -122
- data/lib/jekyll/jekyll-import/rss.rb +0 -63
- data/lib/jekyll/jekyll-import/s9y.rb +0 -59
- data/lib/jekyll/jekyll-import/textpattern.rb +0 -58
- data/lib/jekyll/jekyll-import/tumblr.rb +0 -242
- data/lib/jekyll/jekyll-import/typo.rb +0 -69
- data/lib/jekyll/jekyll-import/wordpress.rb +0 -299
- data/lib/jekyll/jekyll-import/wordpressdotcom.rb +0 -84
@@ -1,112 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'sequel'
|
3
|
-
require 'fileutils'
|
4
|
-
require 'safe_yaml'
|
5
|
-
|
6
|
-
# NOTE: This converter requires Sequel and the MySQL gems.
|
7
|
-
# The MySQL gem can be difficult to install on OS X. Once you have MySQL
|
8
|
-
# installed, running the following commands should work:
|
9
|
-
# $ sudo gem install sequel
|
10
|
-
# $ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
|
11
|
-
|
12
|
-
module JekyllImport
|
13
|
-
module Drupal6
|
14
|
-
# Reads a MySQL database via Sequel and creates a post file for each story
|
15
|
-
# and blog node in table node.
|
16
|
-
QUERY = "SELECT n.nid, \
|
17
|
-
n.title, \
|
18
|
-
nr.body, \
|
19
|
-
n.created, \
|
20
|
-
n.status, \
|
21
|
-
GROUP_CONCAT( td.name SEPARATOR ' ' ) AS 'tags' \
|
22
|
-
FROM node_revisions AS nr, \
|
23
|
-
node AS n \
|
24
|
-
JOIN term_node AS tn ON tn.nid = n.nid \
|
25
|
-
JOIN term_data AS td ON tn.tid = td.tid \
|
26
|
-
WHERE (n.type = 'blog' OR n.type = 'story') \
|
27
|
-
AND n.vid = nr.vid \
|
28
|
-
GROUP BY n.nid"
|
29
|
-
|
30
|
-
def self.process(dbname, user, pass, host = 'localhost', prefix = '')
|
31
|
-
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8')
|
32
|
-
|
33
|
-
if prefix != ''
|
34
|
-
QUERY[" node "] = " " + prefix + "node "
|
35
|
-
QUERY[" node_revisions "] = " " + prefix + "node_revisions "
|
36
|
-
QUERY[" term_node "] = " " + prefix + "term_node "
|
37
|
-
QUERY[" term_data "] = " " + prefix + "term_data "
|
38
|
-
end
|
39
|
-
|
40
|
-
FileUtils.mkdir_p "_posts"
|
41
|
-
FileUtils.mkdir_p "_drafts"
|
42
|
-
|
43
|
-
# Create the refresh layout
|
44
|
-
# Change the refresh url if you customized your permalink config
|
45
|
-
File.open("_layouts/refresh.html", "w") do |f|
|
46
|
-
f.puts <<EOF
|
47
|
-
<!DOCTYPE html>
|
48
|
-
<html>
|
49
|
-
<head>
|
50
|
-
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
51
|
-
<meta http-equiv="refresh" content="0;url={{ page.refresh_to_post_id }}.html" />
|
52
|
-
</head>
|
53
|
-
</html>
|
54
|
-
EOF
|
55
|
-
end
|
56
|
-
|
57
|
-
db[QUERY].each do |post|
|
58
|
-
# Get required fields and construct Jekyll compatible name
|
59
|
-
node_id = post[:nid]
|
60
|
-
title = post[:title]
|
61
|
-
content = post[:body]
|
62
|
-
tags = post[:tags].downcase.strip
|
63
|
-
created = post[:created]
|
64
|
-
time = Time.at(created)
|
65
|
-
is_published = post[:status] == 1
|
66
|
-
dir = is_published ? "_posts" : "_drafts"
|
67
|
-
slug = title.strip.downcase.gsub(/(&|&)/, ' and ').gsub(/[\s\.\/\\]/, '-').gsub(/[^\w-]/, '').gsub(/[-_]{2,}/, '-').gsub(/^[-_]/, '').gsub(/[-_]$/, '')
|
68
|
-
name = time.strftime("%Y-%m-%d-") + slug + '.md'
|
69
|
-
|
70
|
-
# Get the relevant fields as a hash, delete empty fields and convert
|
71
|
-
# to YAML for the header
|
72
|
-
data = {
|
73
|
-
'layout' => 'post',
|
74
|
-
'title' => title.to_s,
|
75
|
-
'created' => created,
|
76
|
-
'categories' => tags
|
77
|
-
}.delete_if { |k,v| v.nil? || v == ''}.each_pair {
|
78
|
-
|k,v| ((v.is_a? String) ? v.force_encoding("UTF-8") : v)
|
79
|
-
}.to_yaml
|
80
|
-
|
81
|
-
# Write out the data and content to file
|
82
|
-
File.open("#{dir}/#{name}", "w") do |f|
|
83
|
-
f.puts data
|
84
|
-
f.puts "---"
|
85
|
-
f.puts content
|
86
|
-
end
|
87
|
-
|
88
|
-
# Make a file to redirect from the old Drupal URL
|
89
|
-
if is_published
|
90
|
-
aliases = db["SELECT dst FROM #{prefix}url_alias WHERE src = ?", "node/#{node_id}"].all
|
91
|
-
|
92
|
-
aliases.push(:dst => "node/#{node_id}")
|
93
|
-
|
94
|
-
aliases.each do |url_alias|
|
95
|
-
FileUtils.mkdir_p url_alias[:dst]
|
96
|
-
File.open("#{url_alias[:dst]}/index.md", "w") do |f|
|
97
|
-
f.puts "---"
|
98
|
-
f.puts "layout: refresh"
|
99
|
-
f.puts "refresh_to_post_id: /#{time.strftime("%Y/%m/%d/") + slug}"
|
100
|
-
f.puts "---"
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
# TODO: Make dirs & files for nodes of type 'page'
|
107
|
-
# Make refresh pages for these as well
|
108
|
-
|
109
|
-
# TODO: Make refresh dirs & files according to entries in url_alias table
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'sequel'
|
3
|
-
require 'fileutils'
|
4
|
-
require 'yaml'
|
5
|
-
|
6
|
-
# NOTE: This converter requires Sequel and the MySQL gems.
|
7
|
-
# The MySQL gem can be difficult to install on OS X. Once you have MySQL
|
8
|
-
# installed, running the following commands should work:
|
9
|
-
# $ sudo gem install sequel
|
10
|
-
# $ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
|
11
|
-
|
12
|
-
module JekyllImport
|
13
|
-
module Drupal7
|
14
|
-
# Reads a MySQL database via Sequel and creates a post file for each post
|
15
|
-
# in wp_posts that has post_status = 'publish'. This restriction is made
|
16
|
-
# because 'draft' posts are not guaranteed to have valid dates.
|
17
|
-
QUERY = "SELECT n.nid, \
|
18
|
-
n.title, \
|
19
|
-
fdb.body_value, \
|
20
|
-
n.created, \
|
21
|
-
n.status \
|
22
|
-
FROM node AS n, \
|
23
|
-
field_data_body AS fdb \
|
24
|
-
WHERE (n.type = 'blog' OR n.type = 'story') \
|
25
|
-
AND n.nid = fdb.entity_id \
|
26
|
-
AND n.vid = fdb.revision_id"
|
27
|
-
|
28
|
-
def self.process(dbname, user, pass, host = 'localhost', prefix = '')
|
29
|
-
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8')
|
30
|
-
|
31
|
-
if prefix != ''
|
32
|
-
QUERY[" node "] = " " + prefix + "node "
|
33
|
-
QUERY[" field_data_body "] = " " + prefix + "field_data_body "
|
34
|
-
end
|
35
|
-
|
36
|
-
FileUtils.mkdir_p "_posts"
|
37
|
-
FileUtils.mkdir_p "_drafts"
|
38
|
-
|
39
|
-
db[QUERY].each do |post|
|
40
|
-
# Get required fields and construct Jekyll compatible name
|
41
|
-
node_id = post[:nid]
|
42
|
-
title = post[:title]
|
43
|
-
content = post[:body_value]
|
44
|
-
created = post[:created]
|
45
|
-
time = Time.at(created)
|
46
|
-
is_published = post[:status] == 1
|
47
|
-
dir = is_published ? "_posts" : "_drafts"
|
48
|
-
slug = title.strip.downcase.gsub(/(&|&)/, ' and ').gsub(/[\s\.\/\\]/, '-').gsub(/[^\w-]/, '').gsub(/[-_]{2,}/, '-').gsub(/^[-_]/, '').gsub(/[-_]$/, '')
|
49
|
-
name = time.strftime("%Y-%m-%d-") + slug + '.md'
|
50
|
-
|
51
|
-
# Get the relevant fields as a hash, delete empty fields and convert
|
52
|
-
# to YAML for the header
|
53
|
-
data = {
|
54
|
-
'layout' => 'default',
|
55
|
-
'title' => title.to_s,
|
56
|
-
'created' => created,
|
57
|
-
}.delete_if { |k,v| v.nil? || v == ''}.to_yaml
|
58
|
-
|
59
|
-
# Write out the data and content to file
|
60
|
-
File.open("#{dir}/#{name}", "w") do |f|
|
61
|
-
f.puts data
|
62
|
-
f.puts "---"
|
63
|
-
f.puts content
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
# TODO: Make dirs & files for nodes of type 'page'
|
69
|
-
# Make refresh pages for these as well
|
70
|
-
|
71
|
-
# TODO: Make refresh dirs & files according to entries in url_alias table
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
# Adapted by Rodrigo Pinto <rodrigopqn@gmail.com>
|
2
|
-
# Based on typo.rb by Toby DiPasquale
|
3
|
-
|
4
|
-
require 'fileutils'
|
5
|
-
require 'rubygems'
|
6
|
-
require 'sequel'
|
7
|
-
|
8
|
-
module JekyllImport
|
9
|
-
module Enki
|
10
|
-
SQL = <<-EOS
|
11
|
-
SELECT p.id,
|
12
|
-
p.title,
|
13
|
-
p.slug,
|
14
|
-
p.body,
|
15
|
-
p.published_at as date,
|
16
|
-
p.cached_tag_list as tags
|
17
|
-
FROM posts p
|
18
|
-
EOS
|
19
|
-
|
20
|
-
# Just working with postgres, but can be easily adapted
|
21
|
-
# to work with both mysql and postgres.
|
22
|
-
def self.process(dbname, user, pass, host = 'localhost')
|
23
|
-
FileUtils.mkdir_p('_posts')
|
24
|
-
db = Sequel.postgres(:database => dbname,
|
25
|
-
:user => user,
|
26
|
-
:password => pass,
|
27
|
-
:host => host,
|
28
|
-
:encoding => 'utf8')
|
29
|
-
|
30
|
-
db[SQL].each do |post|
|
31
|
-
name = [ sprintf("%.04d", post[:date].year),
|
32
|
-
sprintf("%.02d", post[:date].month),
|
33
|
-
sprintf("%.02d", post[:date].day),
|
34
|
-
post[:slug].strip ].join('-')
|
35
|
-
name += '.textile'
|
36
|
-
|
37
|
-
File.open("_posts/#{name}", 'w') do |f|
|
38
|
-
f.puts({ 'layout' => 'post',
|
39
|
-
'title' => post[:title].to_s,
|
40
|
-
'enki_id' => post[:id],
|
41
|
-
'categories' => post[:tags]
|
42
|
-
}.delete_if { |k, v| v.nil? || v == '' }.to_yaml)
|
43
|
-
f.puts '---'
|
44
|
-
f.puts post[:body].delete("\r")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
# Usage:
|
2
|
-
# (Local file)
|
3
|
-
# ruby -r 'jekyll/jekyll-import/rss' -e "JekyllImport::GoogleReader.process(:source => './somefile/on/your/computer.xml')"
|
4
|
-
|
5
|
-
require 'rss'
|
6
|
-
require 'open-uri'
|
7
|
-
require 'fileutils'
|
8
|
-
require 'safe_yaml'
|
9
|
-
|
10
|
-
require 'rexml/document'
|
11
|
-
require 'date'
|
12
|
-
|
13
|
-
module JekyllImport
|
14
|
-
module GoogleReader
|
15
|
-
def self.validate(options)
|
16
|
-
if !options[:source]
|
17
|
-
abort "Missing mandatory option --source."
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
# Process the import.
|
22
|
-
#
|
23
|
-
# source - a URL or a local file String.
|
24
|
-
#
|
25
|
-
# Returns nothing.
|
26
|
-
def self.process(options)
|
27
|
-
validate(options)
|
28
|
-
|
29
|
-
source = options[:source]
|
30
|
-
|
31
|
-
open(source) do |content|
|
32
|
-
feed = RSS::Parser.parse(content)
|
33
|
-
|
34
|
-
raise "There doesn't appear to be any RSS items at the source (#{source}) provided." unless feed
|
35
|
-
|
36
|
-
feed.items.each do |item|
|
37
|
-
title = item.title.content.to_s
|
38
|
-
formatted_date = Date.parse(item.published.to_s)
|
39
|
-
post_name = title.split(%r{ |!|/|:|&|-|$|,}).map do |i|
|
40
|
-
i.downcase if i != ''
|
41
|
-
end.compact.join('-')
|
42
|
-
name = "#{formatted_date}-#{post_name}"
|
43
|
-
|
44
|
-
header = {
|
45
|
-
'layout' => 'post',
|
46
|
-
'title' => title
|
47
|
-
}
|
48
|
-
|
49
|
-
FileUtils.mkdir_p("_posts")
|
50
|
-
|
51
|
-
File.open("_posts/#{name}.html", "w") do |f|
|
52
|
-
f.puts header.to_yaml
|
53
|
-
f.puts "---\n\n"
|
54
|
-
f.puts item.content.content.to_s
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'sequel'
|
3
|
-
require 'fileutils'
|
4
|
-
require 'safe_yaml'
|
5
|
-
|
6
|
-
# NOTE: This migrator is made for Joomla 1.5 databases.
|
7
|
-
# NOTE: This converter requires Sequel and the MySQL gems.
|
8
|
-
# The MySQL gem can be difficult to install on OS X. Once you have MySQL
|
9
|
-
# installed, running the following commands should work:
|
10
|
-
# $ sudo gem install sequel
|
11
|
-
# $ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
|
12
|
-
|
13
|
-
module JekyllImport
|
14
|
-
module Joomla
|
15
|
-
def self.process(dbname, user, pass, host = 'localhost', table_prefix = 'jos_', section = '1')
|
16
|
-
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8')
|
17
|
-
|
18
|
-
FileUtils.mkdir_p("_posts")
|
19
|
-
|
20
|
-
# Reads a MySQL database via Sequel and creates a post file for each
|
21
|
-
# post in wp_posts that has post_status = 'publish'. This restriction is
|
22
|
-
# made because 'draft' posts are not guaranteed to have valid dates.
|
23
|
-
query = "SELECT `title`, `alias`, CONCAT(`introtext`,`fulltext`) as content, `created`, `id` FROM #{table_prefix}content WHERE state = '0' OR state = '1' AND sectionid = '#{section}'"
|
24
|
-
|
25
|
-
db[query].each do |post|
|
26
|
-
# Get required fields and construct Jekyll compatible name.
|
27
|
-
title = post[:title]
|
28
|
-
slug = post[:alias]
|
29
|
-
date = post[:created]
|
30
|
-
content = post[:content]
|
31
|
-
name = "%02d-%02d-%02d-%s.markdown" % [date.year, date.month, date.day,
|
32
|
-
slug]
|
33
|
-
|
34
|
-
# Get the relevant fields as a hash, delete empty fields and convert
|
35
|
-
# to YAML for the header.
|
36
|
-
data = {
|
37
|
-
'layout' => 'post',
|
38
|
-
'title' => title.to_s,
|
39
|
-
'joomla_id' => post[:id],
|
40
|
-
'joomla_url' => post[:alias],
|
41
|
-
'date' => date
|
42
|
-
}.delete_if { |k,v| v.nil? || v == '' }.to_yaml
|
43
|
-
|
44
|
-
# Write out the data and content to file
|
45
|
-
File.open("_posts/#{name}", "w") do |f|
|
46
|
-
f.puts data
|
47
|
-
f.puts "---"
|
48
|
-
f.puts content
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'safe_yaml'
|
2
|
-
require 'fileutils'
|
3
|
-
|
4
|
-
module JekyllImport
|
5
|
-
module Marley
|
6
|
-
def self.regexp
|
7
|
-
{ :id => /^\d{0,4}-{0,1}(.*)$/,
|
8
|
-
:title => /^#\s*(.*)\s+$/,
|
9
|
-
:title_with_date => /^#\s*(.*)\s+\(([0-9\/]+)\)$/,
|
10
|
-
:published_on => /.*\s+\(([0-9\/]+)\)$/,
|
11
|
-
:perex => /^([^\#\n]+\n)$/,
|
12
|
-
:meta => /^\{\{\n(.*)\}\}\n$/mi # Multiline Regexp
|
13
|
-
}
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.process(marley_data_dir)
|
17
|
-
raise ArgumentError, "marley dir #{marley_data_dir} not found" unless File.directory?(marley_data_dir)
|
18
|
-
|
19
|
-
FileUtils.mkdir_p "_posts"
|
20
|
-
|
21
|
-
posts = 0
|
22
|
-
Dir["#{marley_data_dir}/**/*.txt"].each do |f|
|
23
|
-
next unless File.exists?(f)
|
24
|
-
|
25
|
-
#copied over from marley's app/lib/post.rb
|
26
|
-
file_content = File.read(f)
|
27
|
-
meta_content = file_content.slice!( self.regexp[:meta] )
|
28
|
-
body = file_content.sub( self.regexp[:title], '').sub( self.regexp[:perex], '').strip
|
29
|
-
|
30
|
-
title = file_content.scan( self.regexp[:title] ).first.to_s.strip
|
31
|
-
prerex = file_content.scan( self.regexp[:perex] ).first.to_s.strip
|
32
|
-
published_on = DateTime.parse( post[:published_on] ) rescue File.mtime( File.dirname(f) )
|
33
|
-
meta = ( meta_content ) ? YAML::load( meta_content.scan( self.regexp[:meta]).to_s ) : {}
|
34
|
-
meta['title'] = title
|
35
|
-
meta['layout'] = 'post'
|
36
|
-
|
37
|
-
formatted_date = published_on.strftime('%Y-%m-%d')
|
38
|
-
post_name = File.dirname(f).split(%r{/}).last.gsub(/\A\d+-/, '')
|
39
|
-
|
40
|
-
name = "#{formatted_date}-#{post_name}"
|
41
|
-
File.open("_posts/#{name}.markdown", "w") do |f|
|
42
|
-
f.puts meta.to_yaml
|
43
|
-
f.puts "---\n"
|
44
|
-
f.puts "\n#{prerex}\n\n" if prerex
|
45
|
-
f.puts body
|
46
|
-
end
|
47
|
-
posts += 1
|
48
|
-
end
|
49
|
-
"Created #{posts} posts!"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
# Quickly hacked together my Michael Ivey
|
2
|
-
# Based on mt.rb by Nick Gerakines, open source and publically
|
3
|
-
# available under the MIT license. Use this module at your own risk.
|
4
|
-
|
5
|
-
require 'rubygems'
|
6
|
-
require 'sequel'
|
7
|
-
require 'fastercsv'
|
8
|
-
require 'fileutils'
|
9
|
-
require File.join(File.dirname(__FILE__),"csv.rb")
|
10
|
-
|
11
|
-
# NOTE: This converter requires Sequel and the MySQL gems.
|
12
|
-
# The MySQL gem can be difficult to install on OS X. Once you have MySQL
|
13
|
-
# installed, running the following commands should work:
|
14
|
-
# $ sudo gem install sequel
|
15
|
-
# $ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
|
16
|
-
|
17
|
-
module JekyllImport
|
18
|
-
module Mephisto
|
19
|
-
#Accepts a hash with database config variables, exports mephisto posts into a csv
|
20
|
-
#export PGPASSWORD if you must
|
21
|
-
def self.postgres(c)
|
22
|
-
sql = <<-SQL
|
23
|
-
BEGIN;
|
24
|
-
CREATE TEMP TABLE jekyll AS
|
25
|
-
SELECT title, permalink, body, published_at, filter FROM contents
|
26
|
-
WHERE user_id = 1 AND type = 'Article' ORDER BY published_at;
|
27
|
-
COPY jekyll TO STDOUT WITH CSV HEADER;
|
28
|
-
ROLLBACK;
|
29
|
-
SQL
|
30
|
-
command = %Q(psql -h #{c[:host] || "localhost"} -c "#{sql.strip}" #{c[:database]} #{c[:username]} -o #{c[:filename] || "posts.csv"})
|
31
|
-
puts command
|
32
|
-
`#{command}`
|
33
|
-
CSV.process
|
34
|
-
end
|
35
|
-
|
36
|
-
# This query will pull blog posts from all entries across all blogs. If
|
37
|
-
# you've got unpublished, deleted or otherwise hidden posts please sift
|
38
|
-
# through the created posts to make sure nothing is accidently published.
|
39
|
-
QUERY = "SELECT id, \
|
40
|
-
permalink, \
|
41
|
-
body, \
|
42
|
-
published_at, \
|
43
|
-
title \
|
44
|
-
FROM contents \
|
45
|
-
WHERE user_id = 1 AND \
|
46
|
-
type = 'Article' AND \
|
47
|
-
published_at IS NOT NULL \
|
48
|
-
ORDER BY published_at"
|
49
|
-
|
50
|
-
def self.process(dbname, user, pass, host = 'localhost')
|
51
|
-
db = Sequel.mysql(dbname, :user => user,
|
52
|
-
:password => pass,
|
53
|
-
:host => host,
|
54
|
-
:encoding => 'utf8')
|
55
|
-
|
56
|
-
FileUtils.mkdir_p "_posts"
|
57
|
-
|
58
|
-
db[QUERY].each do |post|
|
59
|
-
title = post[:title]
|
60
|
-
slug = post[:permalink]
|
61
|
-
date = post[:published_at]
|
62
|
-
content = post[:body]
|
63
|
-
|
64
|
-
# Ideally, this script would determine the post format (markdown,
|
65
|
-
# html, etc) and create files with proper extensions. At this point
|
66
|
-
# it just assumes that markdown will be acceptable.
|
67
|
-
name = [date.year, date.month, date.day, slug].join('-') + ".markdown"
|
68
|
-
|
69
|
-
data = {
|
70
|
-
'layout' => 'post',
|
71
|
-
'title' => title.to_s,
|
72
|
-
'mt_id' => post[:entry_id],
|
73
|
-
}.delete_if { |k,v| v.nil? || v == ''}.to_yaml
|
74
|
-
|
75
|
-
File.open("_posts/#{name}", "w") do |f|
|
76
|
-
f.puts data
|
77
|
-
f.puts "---"
|
78
|
-
f.puts content
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|