jekyll-import 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll-import/importers/wordpress.rb +22 -12
- data/lib/jekyll-import/importers/wordpressdotcom.rb +93 -45
- data/lib/jekyll-import/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5109d834df31bbc016f4fa9ed39b543cf7c914e
|
4
|
+
data.tar.gz: 6954fc663c0cd876b3704ddbfb22503d35777820
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4210991177bd53645dc452a866231e90bd7ecfb65832702683f053cf5ee66ce7e01133db3984d436941150408af49e9ba69c3b91cfd2c37c1080d2e2c797249
|
7
|
+
data.tar.gz: 80b9a2d9153efda4337f4245e8b6e7e01ff793b83659c4e149ebc7b40631d0327b46a6bb80f51effcf8da3c1a384899117e72938cb493062510145beb2e49e6e
|
@@ -19,6 +19,7 @@ module JekyllImport
|
|
19
19
|
c.option 'password', '--password PW', "Database user's password (default: "")"
|
20
20
|
c.option 'host', '--host HOST', 'Database host name (default: "localhost")'
|
21
21
|
c.option 'table_prefix', '--table_prefix PREFIX', 'Table prefix name (default: "wp_")'
|
22
|
+
c.option 'site_prefix', '--site_prefix PREFIX', 'Site prefix name (default: "")'
|
22
23
|
c.option 'clean_entities', '--clean_entities', 'Whether to clean entities (default: true)'
|
23
24
|
c.option 'comments', '--comments', 'Whether to import comments (default: true)'
|
24
25
|
c.option 'categories', '--categories', 'Whether to import categories (default: true)'
|
@@ -41,6 +42,9 @@ module JekyllImport
|
|
41
42
|
#
|
42
43
|
# :table_prefix:: Prefix of database tables used by WordPress.
|
43
44
|
# Default: 'wp_'
|
45
|
+
# :site_prefix:: Prefix of database tables used by WordPress
|
46
|
+
# Multisite, eg: 2_.
|
47
|
+
# Default: ''
|
44
48
|
# :clean_entities:: If true, convert non-ASCII characters to HTML
|
45
49
|
# entities in the posts, comments, titles, and
|
46
50
|
# names. Requires the 'htmlentities' gem to
|
@@ -49,9 +53,9 @@ module JekyllImport
|
|
49
53
|
# are saved in the post's YAML front matter.
|
50
54
|
# Default: true.
|
51
55
|
# :categories:: If true, save the post's categories in its
|
52
|
-
# YAML front matter.
|
56
|
+
# YAML front matter. Default: true.
|
53
57
|
# :tags:: If true, save the post's tags in its
|
54
|
-
# YAML front matter.
|
58
|
+
# YAML front matter. Default: true.
|
55
59
|
# :more_excerpt:: If true, when a post has no excerpt but
|
56
60
|
# does have a <!-- more --> tag, use the
|
57
61
|
# preceding post content as the excerpt.
|
@@ -60,6 +64,7 @@ module JekyllImport
|
|
60
64
|
# two HTML anchors with ids "more" and
|
61
65
|
# "more-NNN" (where NNN is the post number).
|
62
66
|
# Default: true.
|
67
|
+
# :extension:: Set the post extension. Default: "html"
|
63
68
|
# :status:: Array of allowed post statuses. Only
|
64
69
|
# posts with matching status will be migrated.
|
65
70
|
# Known statuses are :publish, :draft, :private,
|
@@ -75,13 +80,15 @@ module JekyllImport
|
|
75
80
|
:socket => opts.fetch('socket', nil),
|
76
81
|
:dbname => opts.fetch('dbname', ''),
|
77
82
|
:table_prefix => opts.fetch('table_prefix', 'wp_'),
|
83
|
+
:site_prefix => opts.fetch('site_prefix', nil),
|
78
84
|
:clean_entities => opts.fetch('clean_entities', true),
|
79
85
|
:comments => opts.fetch('comments', true),
|
80
86
|
:categories => opts.fetch('categories', true),
|
81
87
|
:tags => opts.fetch('tags', true),
|
82
88
|
:more_excerpt => opts.fetch('more_excerpt', true),
|
83
89
|
:more_anchor => opts.fetch('more_anchor', true),
|
84
|
-
:
|
90
|
+
:extension => opts.fetch('extension', 'html'),
|
91
|
+
:status => opts.fetch('status', ['publish']).map(&:to_sym) # :draft, :private, :revision
|
85
92
|
}
|
86
93
|
|
87
94
|
if options[:clean_entities]
|
@@ -101,6 +108,7 @@ module JekyllImport
|
|
101
108
|
:socket => options[:socket], :host => options[:host], :encoding => 'utf8')
|
102
109
|
|
103
110
|
px = options[:table_prefix]
|
111
|
+
sx = options[:site_prefix]
|
104
112
|
|
105
113
|
page_name_list = {}
|
106
114
|
|
@@ -110,7 +118,7 @@ module JekyllImport
|
|
110
118
|
posts.post_title AS `title`,
|
111
119
|
posts.post_name AS `slug`,
|
112
120
|
posts.post_parent AS `parent`
|
113
|
-
FROM #{px}posts AS `posts`
|
121
|
+
FROM #{px}#{sx}posts AS `posts`
|
114
122
|
WHERE posts.post_type = 'page'"
|
115
123
|
|
116
124
|
db[page_name_query].each do |page|
|
@@ -140,7 +148,7 @@ module JekyllImport
|
|
140
148
|
users.user_login AS `author_login`,
|
141
149
|
users.user_email AS `author_email`,
|
142
150
|
users.user_url AS `author_url`
|
143
|
-
FROM #{px}posts AS `posts`
|
151
|
+
FROM #{px}#{sx}posts AS `posts`
|
144
152
|
LEFT JOIN #{px}users AS `users`
|
145
153
|
ON posts.post_author = users.ID"
|
146
154
|
|
@@ -162,6 +170,8 @@ module JekyllImport
|
|
162
170
|
|
163
171
|
def self.process_post(post, db, options, page_name_list)
|
164
172
|
px = options[:table_prefix]
|
173
|
+
sx = options[:site_prefix]
|
174
|
+
extension = options[:extension]
|
165
175
|
|
166
176
|
title = post[:title]
|
167
177
|
if options[:clean_entities]
|
@@ -174,8 +184,8 @@ module JekyllImport
|
|
174
184
|
end
|
175
185
|
|
176
186
|
date = post[:date] || Time.now
|
177
|
-
name = "%02d-%02d-%02d-%s
|
178
|
-
|
187
|
+
name = "%02d-%02d-%02d-%s.%s" % [date.year, date.month, date.day,
|
188
|
+
slug, extension]
|
179
189
|
content = post[:content].to_s
|
180
190
|
if options[:clean_entities]
|
181
191
|
content = clean_entities(content)
|
@@ -208,9 +218,9 @@ module JekyllImport
|
|
208
218
|
terms.name AS `name`,
|
209
219
|
ttax.taxonomy AS `type`
|
210
220
|
FROM
|
211
|
-
#{px}terms AS `terms`,
|
212
|
-
#{px}term_relationships AS `trels`,
|
213
|
-
#{px}term_taxonomy AS `ttax`
|
221
|
+
#{px}#{sx}terms AS `terms`,
|
222
|
+
#{px}#{sx}term_relationships AS `trels`,
|
223
|
+
#{px}#{sx}term_taxonomy AS `ttax`
|
214
224
|
WHERE
|
215
225
|
trels.object_id = '#{post[:id]}' AND
|
216
226
|
trels.term_taxonomy_id = ttax.term_taxonomy_id AND
|
@@ -245,7 +255,7 @@ module JekyllImport
|
|
245
255
|
comment_date AS `date`,
|
246
256
|
comment_date_gmt AS `date_gmt`,
|
247
257
|
comment_content AS `content`
|
248
|
-
FROM #{px}comments
|
258
|
+
FROM #{px}#{sx}comments
|
249
259
|
WHERE
|
250
260
|
comment_post_ID = '#{post[:id]}' AND
|
251
261
|
comment_approved != 'spam'"
|
@@ -307,7 +317,7 @@ module JekyllImport
|
|
307
317
|
}.delete_if { |k,v| v.nil? || v == '' }.to_yaml
|
308
318
|
|
309
319
|
if post[:type] == 'page'
|
310
|
-
filename = page_path(post[:id], page_name_list) +
|
320
|
+
filename = page_path(post[:id], page_name_list) + "index.#{extension}"
|
311
321
|
FileUtils.mkdir_p(File.dirname(filename))
|
312
322
|
elsif post[:status] == 'draft'
|
313
323
|
filename = "_drafts/#{slug}.md"
|
@@ -30,7 +30,7 @@ module JekyllImport
|
|
30
30
|
images.each do |i|
|
31
31
|
uri = i["src"]
|
32
32
|
|
33
|
-
i["src"] =
|
33
|
+
i["src"] = "{{ site.baseurl }}/%s/%s" % [assets_folder, File.basename(uri)]
|
34
34
|
dst = File.join(assets_folder, File.basename(uri))
|
35
35
|
puts " " + uri
|
36
36
|
if File.exist?(dst)
|
@@ -50,6 +50,75 @@ module JekyllImport
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
+
class Item
|
54
|
+
def initialize(node)
|
55
|
+
@node = node
|
56
|
+
end
|
57
|
+
|
58
|
+
def text_for(path)
|
59
|
+
@node.at(path).inner_text
|
60
|
+
end
|
61
|
+
|
62
|
+
def title
|
63
|
+
@title ||= text_for(:title).strip
|
64
|
+
end
|
65
|
+
|
66
|
+
def permalink_title
|
67
|
+
post_name = text_for('wp:post_name')
|
68
|
+
# Fallback to "prettified" title if post_name is empty (can happen)
|
69
|
+
@permalink_title ||= if post_name.empty?
|
70
|
+
WordpressDotCom.sluggify(title)
|
71
|
+
else
|
72
|
+
post_name
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def published_at
|
77
|
+
if published?
|
78
|
+
@published_at ||= Time.parse(text_for('wp:post_date'))
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def status
|
83
|
+
@status ||= text_for('wp:status')
|
84
|
+
end
|
85
|
+
|
86
|
+
def post_type
|
87
|
+
@post_type ||= text_for('wp:post_type')
|
88
|
+
end
|
89
|
+
|
90
|
+
def file_name
|
91
|
+
@file_name ||= if published?
|
92
|
+
"#{published_at.strftime('%Y-%m-%d')}-#{permalink_title}.html"
|
93
|
+
else
|
94
|
+
"#{permalink_title}.html"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def directory_name
|
99
|
+
@directory_name ||= if !published? && post_type == 'post'
|
100
|
+
'_drafts'
|
101
|
+
else
|
102
|
+
"_#{post_type}s"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def published?
|
107
|
+
@published ||= (status == 'publish')
|
108
|
+
end
|
109
|
+
|
110
|
+
def excerpt
|
111
|
+
@excerpt ||= begin
|
112
|
+
text = Hpricot(text_for('excerpt:encoded')).inner_text
|
113
|
+
if text.empty?
|
114
|
+
nil
|
115
|
+
else
|
116
|
+
text
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
53
122
|
def self.process(options)
|
54
123
|
source = options.fetch('source', "wordpress.xml")
|
55
124
|
fetch = !options.fetch('no_fetch_images', false)
|
@@ -71,77 +140,56 @@ module JekyllImport
|
|
71
140
|
end
|
72
141
|
] rescue {}
|
73
142
|
|
74
|
-
(doc/:channel/:item).each do |
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
if permalink_title == ""
|
79
|
-
permalink_title = sluggify(title)
|
80
|
-
end
|
81
|
-
|
82
|
-
date = Time.parse(item.at('wp:post_date').inner_text)
|
83
|
-
status = item.at('wp:status').inner_text
|
84
|
-
|
85
|
-
if status == "publish"
|
86
|
-
published = true
|
87
|
-
else
|
88
|
-
published = false
|
89
|
-
end
|
90
|
-
|
91
|
-
type = item.at('wp:post_type').inner_text
|
92
|
-
categories = item.search('category[@domain="category"]').map{|c| c.inner_text}.reject{|c| c == 'Uncategorized'}.uniq
|
93
|
-
tags = item.search('category[@domain="post_tag"]').map{|t| t.inner_text}.uniq
|
143
|
+
(doc/:channel/:item).each do |node|
|
144
|
+
item = Item.new(node)
|
145
|
+
categories = node.search('category[@domain="category"]').map(&:inner_text).reject{|c| c == 'Uncategorized'}.uniq
|
146
|
+
tags = node.search('category[@domain="post_tag"]').map(&:inner_text).uniq
|
94
147
|
|
95
148
|
metas = Hash.new
|
96
|
-
|
149
|
+
node.search("wp:postmeta").each do |meta|
|
97
150
|
key = meta.at('wp:meta_key').inner_text
|
98
151
|
value = meta.at('wp:meta_value').inner_text
|
99
152
|
metas[key] = value
|
100
153
|
end
|
101
154
|
|
102
|
-
author_login = item.
|
155
|
+
author_login = item.text_for('dc:creator').strip
|
103
156
|
|
104
|
-
name = "#{date.strftime('%Y-%m-%d')}-#{permalink_title}.html"
|
105
157
|
header = {
|
106
|
-
'layout'
|
107
|
-
'title'
|
108
|
-
'date'
|
158
|
+
'layout' => item.post_type,
|
159
|
+
'title' => item.title,
|
160
|
+
'date' => item.published_at,
|
161
|
+
'type' => item.post_type,
|
162
|
+
'published' => item.published?,
|
163
|
+
'status' => item.status,
|
109
164
|
'categories' => categories,
|
110
|
-
'tags'
|
111
|
-
'
|
112
|
-
'
|
113
|
-
'published' => published,
|
114
|
-
'meta' => metas,
|
115
|
-
'author' => authors[author_login]
|
165
|
+
'tags' => tags,
|
166
|
+
'meta' => metas,
|
167
|
+
'author' => authors[author_login]
|
116
168
|
}
|
117
169
|
|
118
170
|
begin
|
119
|
-
content = Hpricot(item.
|
120
|
-
excerpt =
|
121
|
-
|
122
|
-
if excerpt
|
123
|
-
header['excerpt'] = excerpt
|
124
|
-
end
|
171
|
+
content = Hpricot(item.text_for('content:encoded'))
|
172
|
+
header['excerpt'] = item.excerpt if item.excerpt
|
125
173
|
|
126
174
|
if fetch
|
127
|
-
download_images(title, content, assets_folder)
|
175
|
+
download_images(item.title, content, assets_folder)
|
128
176
|
end
|
129
177
|
|
130
|
-
FileUtils.mkdir_p
|
131
|
-
File.open(
|
178
|
+
FileUtils.mkdir_p item.directory_name
|
179
|
+
File.open(File.join(item.directory_name, item.file_name), "w") do |f|
|
132
180
|
f.puts header.to_yaml
|
133
181
|
f.puts '---'
|
134
182
|
f.puts Util.wpautop(content.to_html)
|
135
183
|
end
|
136
184
|
rescue => e
|
137
185
|
puts "Couldn't import post!"
|
138
|
-
puts "Title: #{title}"
|
139
|
-
puts "Name/Slug: #{
|
186
|
+
puts "Title: #{item.title}"
|
187
|
+
puts "Name/Slug: #{item.file_name}\n"
|
140
188
|
puts "Error: #{e.message}"
|
141
189
|
next
|
142
190
|
end
|
143
191
|
|
144
|
-
import_count[
|
192
|
+
import_count[item.post_type] += 1
|
145
193
|
end
|
146
194
|
|
147
195
|
import_count.each do |key, value|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-import
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Preston-Werner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -349,7 +349,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
349
349
|
version: '0'
|
350
350
|
requirements: []
|
351
351
|
rubyforge_project:
|
352
|
-
rubygems_version: 2.2.
|
352
|
+
rubygems_version: 2.2.3
|
353
353
|
signing_key:
|
354
354
|
specification_version: 2
|
355
355
|
summary: Import command for Jekyll (static site generator).
|