Now creates _<directory> for each post type (e.g. _posts, _pages, _attachments)
This commit is contained in:
parent
29c4808f2a
commit
eb6a2b9bd0
|
@ -11,9 +11,7 @@ module Jekyll
|
||||||
# wordpress.com blog (/wp-admin/export.php).
|
# wordpress.com blog (/wp-admin/export.php).
|
||||||
module WordpressDotCom
|
module WordpressDotCom
|
||||||
def self.process(filename = "wordpress.xml")
|
def self.process(filename = "wordpress.xml")
|
||||||
FileUtils.mkdir_p "_posts"
|
import_count = Hash.new
|
||||||
posts = 0
|
|
||||||
|
|
||||||
doc = Hpricot::XML(File.read(filename))
|
doc = Hpricot::XML(File.read(filename))
|
||||||
|
|
||||||
(doc/:channel/:item).each do |item|
|
(doc/:channel/:item).each do |item|
|
||||||
|
@ -26,10 +24,11 @@ module Jekyll
|
||||||
|
|
||||||
date = Time.parse(item.at('wp:post_date').inner_text)
|
date = Time.parse(item.at('wp:post_date').inner_text)
|
||||||
status = item.at('wp:status').inner_text
|
status = item.at('wp:status').inner_text
|
||||||
if status == "draft"
|
|
||||||
published = false
|
if status == "publish"
|
||||||
else
|
|
||||||
published = true
|
published = true
|
||||||
|
else
|
||||||
|
published = false
|
||||||
end
|
end
|
||||||
|
|
||||||
type = item.at('wp:post_type').inner_text
|
type = item.at('wp:post_type').inner_text
|
||||||
|
@ -44,7 +43,7 @@ module Jekyll
|
||||||
|
|
||||||
name = "#{date.strftime('%Y-%m-%d')}-#{permalink_title}.html"
|
name = "#{date.strftime('%Y-%m-%d')}-#{permalink_title}.html"
|
||||||
header = {
|
header = {
|
||||||
'layout' => 'post',
|
'layout' => type,
|
||||||
'title' => title,
|
'title' => title,
|
||||||
'tags' => tags,
|
'tags' => tags,
|
||||||
'status' => status,
|
'status' => status,
|
||||||
|
@ -53,16 +52,22 @@ module Jekyll
|
||||||
'meta' => metas
|
'meta' => metas
|
||||||
}
|
}
|
||||||
|
|
||||||
File.open("_posts/#{name}", "w") do |f|
|
FileUtils.mkdir_p "_#{type}s"
|
||||||
|
File.open("_#{type}s/#{name}", "w") do |f|
|
||||||
f.puts header.to_yaml
|
f.puts header.to_yaml
|
||||||
f.puts '---'
|
f.puts '---'
|
||||||
f.puts item.at('content:encoded').inner_text
|
f.puts item.at('content:encoded').inner_text
|
||||||
end
|
end
|
||||||
|
if import_count[type] == nil
|
||||||
posts += 1
|
import_count[type] = 1
|
||||||
|
else
|
||||||
|
import_count[type] += 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
puts "Imported #{posts} posts"
|
import_count.each do |key, value|
|
||||||
|
puts "Imported #{value} #{key}s"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue