Merge remote-tracking branch 'elia/master' into devel
This commit is contained in:
commit
d2814cf750
|
@ -4,6 +4,7 @@
|
||||||
* Bundler support
|
* Bundler support
|
||||||
* Use English library to avoid hoops (#292)
|
* Use English library to avoid hoops (#292)
|
||||||
* Add Posterous importer (#254)
|
* Add Posterous importer (#254)
|
||||||
|
* Fixes for Wordpress importer (#274, #252)
|
||||||
* Bug Fixes
|
* Bug Fixes
|
||||||
* Secure additional path exploits
|
* Secure additional path exploits
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
|
# coding: utf-8
|
||||||
|
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
require 'hpricot'
|
require 'hpricot'
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
|
require 'yaml'
|
||||||
# This importer takes a wordpress.xml file,
|
|
||||||
# which can be exported from your
|
|
||||||
# wordpress.com blog (/wp-admin/export.php)
|
|
||||||
|
|
||||||
module Jekyll
|
module Jekyll
|
||||||
|
|
||||||
|
# This importer takes a wordpress.xml file,
|
||||||
|
# which can be exported from your
|
||||||
|
# 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"
|
FileUtils.mkdir_p "_posts"
|
||||||
|
@ -15,24 +18,28 @@ module Jekyll
|
||||||
doc = Hpricot::XML(File.read(filename))
|
doc = Hpricot::XML(File.read(filename))
|
||||||
|
|
||||||
(doc/:channel/:item).each do |item|
|
(doc/:channel/:item).each do |item|
|
||||||
title = item.at(:title).inner_text
|
title = item.at(:title).inner_text.strip
|
||||||
name = "#{Date.parse((doc/:channel/:item).first.at(:pubDate).inner_text).to_s("%Y-%m-%d")}-#{title.downcase.gsub('[^a-z0-9]', '-')}.html"
|
permalink_title = item.at('wp:post_name').inner_text
|
||||||
|
date = Time.parse(item.at(:pubDate).inner_text)
|
||||||
|
tags = (item/:category).map{|c| c.inner_text}.reject{|c| c == 'Uncategorized'}.uniq
|
||||||
|
name = "#{date.strftime('%Y-%m-%d')}-#{permalink_title}.html"
|
||||||
|
header = {
|
||||||
|
'layout' => 'post',
|
||||||
|
'title' => title,
|
||||||
|
'tags' => tags
|
||||||
|
}
|
||||||
|
|
||||||
File.open("_posts/#{name}", "w") do |f|
|
File.open("_posts/#{name}", "w") do |f|
|
||||||
f.puts <<-HEADER
|
f.puts header.to_yaml
|
||||||
---
|
f.puts '---'
|
||||||
layout: post
|
|
||||||
title: #{title}
|
|
||||||
---
|
|
||||||
|
|
||||||
HEADER
|
|
||||||
f.puts item.at('content:encoded').inner_text
|
f.puts item.at('content:encoded').inner_text
|
||||||
end
|
end
|
||||||
|
|
||||||
posts += 1
|
posts += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
"Imported #{posts} posts"
|
puts "Imported #{posts} posts"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
Loading…
Reference in New Issue