bunto-import 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +21 -21
- data/README.markdown +33 -33
- data/lib/bunto-import.rb +49 -49
- data/lib/bunto-import/importer.rb +26 -26
- data/lib/bunto-import/importers.rb +10 -10
- data/lib/bunto-import/importers/behance.rb +80 -80
- data/lib/bunto-import/importers/blogger.rb +330 -264
- data/lib/bunto-import/importers/csv.rb +96 -96
- data/lib/bunto-import/importers/drupal6.rb +53 -139
- data/lib/bunto-import/importers/drupal7.rb +54 -111
- data/lib/bunto-import/importers/drupal_common.rb +157 -0
- data/lib/bunto-import/importers/easyblog.rb +96 -96
- data/lib/bunto-import/importers/enki.rb +74 -74
- data/lib/bunto-import/importers/ghost.rb +68 -68
- data/lib/bunto-import/importers/google_reader.rb +64 -64
- data/lib/bunto-import/importers/joomla.rb +92 -90
- data/lib/bunto-import/importers/joomla3.rb +91 -91
- data/lib/bunto-import/importers/jrnl.rb +125 -125
- data/lib/bunto-import/importers/marley.rb +72 -72
- data/lib/bunto-import/importers/mephisto.rb +99 -99
- data/lib/bunto-import/importers/mt.rb +257 -257
- data/lib/bunto-import/importers/posterous.rb +130 -130
- data/lib/bunto-import/importers/rss.rb +62 -62
- data/lib/bunto-import/importers/s9y.rb +60 -60
- data/lib/bunto-import/importers/s9y_database.rb +363 -0
- data/lib/bunto-import/importers/textpattern.rb +70 -70
- data/lib/bunto-import/importers/tumblr.rb +300 -289
- data/lib/bunto-import/importers/typo.rb +88 -88
- data/lib/bunto-import/importers/wordpress.rb +372 -372
- data/lib/bunto-import/importers/wordpressdotcom.rb +207 -207
- data/lib/bunto-import/util.rb +76 -76
- data/lib/bunto-import/version.rb +3 -3
- data/lib/bunto/commands/import.rb +79 -79
- metadata +84 -54
@@ -1,264 +1,330 @@
|
|
1
|
-
module BuntoImport
|
2
|
-
module Importers
|
3
|
-
class Blogger < Importer
|
4
|
-
def self.specify_options(c)
|
5
|
-
c.option 'source', '--source NAME', 'The XML file (blog-MM-DD-YYYY.xml) path to import'
|
6
|
-
c.option 'no-blogger-info', '--no-blogger-info', 'not to leave blogger-URL info (id and old URL) in the front matter (default: false)'
|
7
|
-
c.option 'replace-internal-link', '--replace-internal-link', 'replace internal links using the post_url liquid tag. (default: false)'
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
rexml/
|
22
|
-
rexml/
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
"
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
extend
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
when '
|
114
|
-
if @in_entry_elem
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
1
|
+
module BuntoImport
|
2
|
+
module Importers
|
3
|
+
class Blogger < Importer
|
4
|
+
def self.specify_options(c)
|
5
|
+
c.option 'source', '--source NAME', 'The XML file (blog-MM-DD-YYYY.xml) path to import'
|
6
|
+
c.option 'no-blogger-info', '--no-blogger-info', 'not to leave blogger-URL info (id and old URL) in the front matter (default: false)'
|
7
|
+
c.option 'replace-internal-link', '--replace-internal-link', 'replace internal links using the post_url liquid tag. (default: false)'
|
8
|
+
c.option 'comments', '--comments', 'import comments to _comments collection'
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.validate(options)
|
12
|
+
if options['source'].nil?
|
13
|
+
raise 'Missing mandatory option: --source'
|
14
|
+
elsif not File.exist?(options['source'])
|
15
|
+
raise Errno::ENOENT, "File not found: #{options['source']}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.require_deps
|
20
|
+
BuntoImport.require_with_fallback(%w[
|
21
|
+
rexml/document
|
22
|
+
rexml/streamlistener
|
23
|
+
rexml/parsers/streamparser
|
24
|
+
uri
|
25
|
+
time
|
26
|
+
fileutils
|
27
|
+
safe_yaml
|
28
|
+
open-uri
|
29
|
+
])
|
30
|
+
end
|
31
|
+
|
32
|
+
# Process the import.
|
33
|
+
#
|
34
|
+
# source:: a local file String (or IO object for internal use purpose)..
|
35
|
+
# no-blogger-info:: a boolean if not leave blogger info (id and original URL).
|
36
|
+
# replace-internal-link:: a boolean if replace internal link
|
37
|
+
#
|
38
|
+
# Returns nothing.
|
39
|
+
def self.process(options)
|
40
|
+
source = options.fetch('source')
|
41
|
+
|
42
|
+
listener = BloggerAtomStreamListener.new
|
43
|
+
|
44
|
+
listener.leave_blogger_info = ! options.fetch('no-blogger-info', false),
|
45
|
+
listener.comments = options.fetch('comments', false),
|
46
|
+
|
47
|
+
File.open(source, 'r') do |f|
|
48
|
+
f.flock(File::LOCK_SH)
|
49
|
+
REXML::Parsers::StreamParser.new(f, listener).parse()
|
50
|
+
end
|
51
|
+
|
52
|
+
options['original-url-base'] = listener.original_url_base
|
53
|
+
|
54
|
+
postprocess(options)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Post-process after import.
|
58
|
+
#
|
59
|
+
# replace-internal-link:: a boolean if replace internal link
|
60
|
+
#
|
61
|
+
# Returns nothing.
|
62
|
+
def self.postprocess(options)
|
63
|
+
# Replace internal link URL
|
64
|
+
if options.fetch('replace-internal-link', false)
|
65
|
+
original_url_base = options.fetch('original-url-base', nil)
|
66
|
+
if original_url_base
|
67
|
+
orig_url_pattern = Regexp.new(" href=([\"\'])(?:#{Regexp.escape(original_url_base)})?/([0-9]{4})/([0-9]{2})/([^\"\']+\.html)\\1")
|
68
|
+
|
69
|
+
Dir.glob('_posts/*.*') do |filename|
|
70
|
+
body = nil
|
71
|
+
File.open(filename, 'r') do |f|
|
72
|
+
f.flock(File::LOCK_SH)
|
73
|
+
body = f.read
|
74
|
+
end
|
75
|
+
|
76
|
+
body.gsub!(orig_url_pattern) do
|
77
|
+
# for post_url
|
78
|
+
quote = $1
|
79
|
+
post_file = Dir.glob("_posts/#{$2}-#{$3}-*-#{$4.to_s.tr('/', '-')}").first
|
80
|
+
raise "Could not found: _posts/#{$2}-#{$3}-*-#{$4.to_s.tr('/', '-')}" if post_file.nil?
|
81
|
+
" href=#{quote}{{ site.baseurl }}{% post_url #{File.basename(post_file, '.html')} %}#{quote}"
|
82
|
+
end
|
83
|
+
|
84
|
+
File.open(filename, 'w') do |f|
|
85
|
+
f.flock(File::LOCK_EX)
|
86
|
+
f << body
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class BloggerAtomStreamListener
|
94
|
+
def initialize
|
95
|
+
# use `extend` instead of `include` to use `require_deps` instead of `require`.
|
96
|
+
extend REXML::StreamListener
|
97
|
+
extend BloggerAtomStreamListenerMethods
|
98
|
+
|
99
|
+
@leave_blogger_info = true
|
100
|
+
@comments = false
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
module BloggerAtomStreamListenerMethods
|
105
|
+
attr_accessor :leave_blogger_info, :comments
|
106
|
+
attr_reader :original_url_base
|
107
|
+
|
108
|
+
def tag_start(tag, attrs)
|
109
|
+
@tag_bread = [] unless @tag_bread
|
110
|
+
@tag_bread.push(tag)
|
111
|
+
|
112
|
+
case tag
|
113
|
+
when 'entry'
|
114
|
+
raise 'nest entry element' if @in_entry_elem
|
115
|
+
@in_entry_elem = {:meta => {}, :body => nil}
|
116
|
+
when 'title'
|
117
|
+
if @in_entry_elem
|
118
|
+
raise 'only <title type="text"></title> is supported' if attrs['type'] != 'text'
|
119
|
+
end
|
120
|
+
when 'category'
|
121
|
+
if @in_entry_elem
|
122
|
+
if attrs['scheme'] == 'http://www.blogger.com/atom/ns#'
|
123
|
+
@in_entry_elem[:meta][:category] = [] unless @in_entry_elem[:meta][:category]
|
124
|
+
@in_entry_elem[:meta][:category] << attrs['term']
|
125
|
+
elsif attrs['scheme'] == 'http://schemas.google.com/g/2005#kind'
|
126
|
+
kind = attrs['term']
|
127
|
+
kind.sub!(Regexp.new("^http://schemas\\.google\\.com/blogger/2008/kind\\#"), '')
|
128
|
+
@in_entry_elem[:meta][:kind] = kind
|
129
|
+
end
|
130
|
+
end
|
131
|
+
when 'content'
|
132
|
+
if @in_entry_elem
|
133
|
+
@in_entry_elem[:meta][:content_type] = attrs['type']
|
134
|
+
end
|
135
|
+
when 'link'
|
136
|
+
if @in_entry_elem
|
137
|
+
if attrs['rel'] == 'alternate' && attrs['type'] == 'text/html'
|
138
|
+
@in_entry_elem[:meta][:original_url] = attrs['href']
|
139
|
+
elsif attrs['rel'] == 'replies' && attrs['type'] == 'text/html'
|
140
|
+
unless @in_entry_elem[:meta][:original_url]
|
141
|
+
@in_entry_elem[:meta][:original_url] = attrs['href'].sub(/\#comment-form$/, '')
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
when 'media:thumbnail'
|
146
|
+
if @in_entry_elem
|
147
|
+
@in_entry_elem[:meta][:thumbnail] = attrs['url']
|
148
|
+
end
|
149
|
+
when 'thr:in-reply-to'
|
150
|
+
if @in_entry_elem
|
151
|
+
@in_entry_elem[:meta][:post_id] = attrs['ref']
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def text(text)
|
157
|
+
if @in_entry_elem
|
158
|
+
case @tag_bread.last
|
159
|
+
when 'id'
|
160
|
+
@in_entry_elem[:meta][:id] = text
|
161
|
+
when 'published'
|
162
|
+
@in_entry_elem[:meta][:published] = text
|
163
|
+
when 'updated'
|
164
|
+
@in_entry_elem[:meta][:updated] = text
|
165
|
+
when 'title'
|
166
|
+
@in_entry_elem[:meta][:title] = text
|
167
|
+
when 'content'
|
168
|
+
@in_entry_elem[:body] = text
|
169
|
+
when 'name'
|
170
|
+
if @tag_bread[-2..-1] == %w[author name]
|
171
|
+
@in_entry_elem[:meta][:author] = text
|
172
|
+
end
|
173
|
+
when 'app:draft'
|
174
|
+
if @tag_bread[-2..-1] == %w[app:control app:draft]
|
175
|
+
@in_entry_elem[:meta][:draft] = true if text == 'yes'
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def tag_end(tag)
|
182
|
+
case tag
|
183
|
+
when 'entry'
|
184
|
+
raise 'nest entry element' unless @in_entry_elem
|
185
|
+
|
186
|
+
if @in_entry_elem[:meta][:kind] == 'post'
|
187
|
+
post_data = get_post_data_from_in_entry_elem_info
|
188
|
+
|
189
|
+
if post_data
|
190
|
+
target_dir = '_posts'
|
191
|
+
target_dir = '_drafts' if @in_entry_elem[:meta][:draft]
|
192
|
+
|
193
|
+
FileUtils.mkdir_p(target_dir)
|
194
|
+
|
195
|
+
file_name = URI::decode("#{post_data[:filename]}.html")
|
196
|
+
File.open(File.join(target_dir, file_name), 'w') do |f|
|
197
|
+
f.flock(File::LOCK_EX)
|
198
|
+
|
199
|
+
f << post_data[:header].to_yaml
|
200
|
+
f << "---\n\n"
|
201
|
+
f << post_data[:body]
|
202
|
+
end
|
203
|
+
end
|
204
|
+
elsif @in_entry_elem[:meta][:kind] == 'comment' and @comments
|
205
|
+
post_data = get_post_data_from_in_entry_elem_info
|
206
|
+
|
207
|
+
if post_data
|
208
|
+
target_dir = '_comments'
|
209
|
+
|
210
|
+
FileUtils.mkdir_p(target_dir)
|
211
|
+
|
212
|
+
file_name = URI::decode("#{post_data[:filename]}.html")
|
213
|
+
File.open(File.join(target_dir, file_name), 'w') do |f|
|
214
|
+
f.flock(File::LOCK_EX)
|
215
|
+
|
216
|
+
f << post_data[:header].to_yaml
|
217
|
+
f << "---\n\n"
|
218
|
+
f << post_data[:body]
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
@in_entry_elem = nil
|
224
|
+
end
|
225
|
+
|
226
|
+
@tag_bread.pop
|
227
|
+
end
|
228
|
+
|
229
|
+
def get_post_data_from_in_entry_elem_info
|
230
|
+
if (@in_entry_elem.nil? || ! @in_entry_elem.has_key?(:meta) || ! @in_entry_elem[:meta].has_key?(:kind))
|
231
|
+
nil
|
232
|
+
elsif @in_entry_elem[:meta][:kind] == 'post'
|
233
|
+
timestamp = Time.parse(@in_entry_elem[:meta][:published]).strftime('%Y-%m-%d')
|
234
|
+
if @in_entry_elem[:meta][:original_url]
|
235
|
+
original_uri = URI.parse(@in_entry_elem[:meta][:original_url])
|
236
|
+
original_path = original_uri.path.to_s
|
237
|
+
filename = "%s-%s" %
|
238
|
+
[timestamp,
|
239
|
+
File.basename(original_path, File.extname(original_path))]
|
240
|
+
|
241
|
+
@original_url_base = "#{original_uri.scheme}://#{original_uri.host}"
|
242
|
+
elsif @in_entry_elem[:meta][:draft]
|
243
|
+
# Drafts don't have published urls
|
244
|
+
name = @in_entry_elem[:meta][:title]
|
245
|
+
if name.nil?
|
246
|
+
filename = timestamp
|
247
|
+
else
|
248
|
+
filename = "%s-%s" %
|
249
|
+
[timestamp,
|
250
|
+
CGI.escape(name.downcase).tr('+','-')]
|
251
|
+
end
|
252
|
+
else
|
253
|
+
raise 'Original URL is missing'
|
254
|
+
end
|
255
|
+
|
256
|
+
header = {
|
257
|
+
'layout' => 'post',
|
258
|
+
'title' => @in_entry_elem[:meta][:title],
|
259
|
+
'date' => @in_entry_elem[:meta][:published],
|
260
|
+
'author' => @in_entry_elem[:meta][:author],
|
261
|
+
'tags' => @in_entry_elem[:meta][:category],
|
262
|
+
}
|
263
|
+
header['modified_time'] = @in_entry_elem[:meta][:updated] if @in_entry_elem[:meta][:updated] && @in_entry_elem[:meta][:updated] != @in_entry_elem[:meta][:published]
|
264
|
+
header['thumbnail'] = @in_entry_elem[:meta][:thumbnail] if @in_entry_elem[:meta][:thumbnail]
|
265
|
+
header['blogger_id'] = @in_entry_elem[:meta][:id] if @leave_blogger_info
|
266
|
+
header['blogger_orig_url'] = @in_entry_elem[:meta][:original_url] if @leave_blogger_info && @in_entry_elem[:meta][:original_url]
|
267
|
+
|
268
|
+
body = @in_entry_elem[:body]
|
269
|
+
|
270
|
+
# body escaping associated with liquid
|
271
|
+
if body =~ /{{/
|
272
|
+
body.gsub!(/{{/, '{{ "{{" }}')
|
273
|
+
end
|
274
|
+
if body =~ /{%/
|
275
|
+
body.gsub!(/{%/, '{{ "{%" }}')
|
276
|
+
end
|
277
|
+
|
278
|
+
{ :filename => filename, :header => header, :body => body }
|
279
|
+
elsif @in_entry_elem[:meta][:kind] == 'comment'
|
280
|
+
timestamp = Time.parse(@in_entry_elem[:meta][:published]).strftime('%Y-%m-%d')
|
281
|
+
if @in_entry_elem[:meta][:original_url]
|
282
|
+
if not @comment_seq
|
283
|
+
@comment_seq = 1
|
284
|
+
end
|
285
|
+
|
286
|
+
original_uri = URI.parse(@in_entry_elem[:meta][:original_url])
|
287
|
+
original_path = original_uri.path.to_s
|
288
|
+
filename = "%s-%s-%s" %
|
289
|
+
[timestamp,
|
290
|
+
File.basename(original_path, File.extname(original_path)),
|
291
|
+
@comment_seq]
|
292
|
+
|
293
|
+
@comment_seq = @comment_seq + 1
|
294
|
+
|
295
|
+
@original_url_base = "#{original_uri.scheme}://#{original_uri.host}"
|
296
|
+
else
|
297
|
+
raise 'Original URL is missing'
|
298
|
+
end
|
299
|
+
|
300
|
+
header = {
|
301
|
+
'date' => @in_entry_elem[:meta][:published],
|
302
|
+
'author' => @in_entry_elem[:meta][:author],
|
303
|
+
'blogger_post_id' => @in_entry_elem[:meta][:post_id],
|
304
|
+
}
|
305
|
+
header['modified_time'] = @in_entry_elem[:meta][:updated] if @in_entry_elem[:meta][:updated] && @in_entry_elem[:meta][:updated] != @in_entry_elem[:meta][:published]
|
306
|
+
header['thumbnail'] = @in_entry_elem[:meta][:thumbnail] if @in_entry_elem[:meta][:thumbnail]
|
307
|
+
header['blogger_id'] = @in_entry_elem[:meta][:id] if @leave_blogger_info
|
308
|
+
header['blogger_orig_url'] = @in_entry_elem[:meta][:original_url] if @leave_blogger_info && @in_entry_elem[:meta][:original_url]
|
309
|
+
|
310
|
+
body = @in_entry_elem[:body]
|
311
|
+
|
312
|
+
# body escaping associated with liquid
|
313
|
+
if body =~ /{{/
|
314
|
+
body.gsub!(/{{/, '{{ "{{" }}')
|
315
|
+
end
|
316
|
+
if body =~ /{%/
|
317
|
+
body.gsub!(/{%/, '{{ "{%" }}')
|
318
|
+
end
|
319
|
+
|
320
|
+
{ :filename => filename, :header => header, :body => body }
|
321
|
+
else
|
322
|
+
nil
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
end
|
327
|
+
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|