Sha256: bdf1fca0cfd9684c95ee437d7d8dd7f23d8c0aa891aa9fc2e20a86ce93f4ac83
Contents?: true
Size: 846 Bytes
Versions: 4
Compression:
Stored size: 846 Bytes
Contents
require 'rubygems' require 'hpricot' require 'fileutils' # This importer takes a wordpress.xml file, # which can be exported from your # wordpress.com blog (/wp-admin/export.php) module Jekyll module WordpressDotCom def self.process(filename = "wordpress.xml") FileUtils.mkdir_p "_posts" posts = 0 doc = Hpricot::XML(File.read(filename)) (doc/:channel/:item).each do |item| title = item.at(:title).inner_text name = "#{Date.parse((doc/:channel/:item).first.at(:pubDate).inner_text).to_s("%Y-%m-%d")}-#{title.downcase.gsub('[^a-z0-9]', '-')}.html" File.open("_posts/#{name}", "w") do |f| f.puts <<-HEADER --- layout: post title: #{title} --- HEADER f.puts item.at('content:encoded').inner_text end posts += 1 end "Imported #{posts} posts" end end end
Version data entries
4 entries across 4 versions & 2 rubygems