Module: Jekyll::WordpressDotCom

Defined in:
lib/jekyll/migrators/wordpress.com.rb

Class Method Summary collapse

Class Method Details

.process(filename = "wordpress.xml") ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/jekyll/migrators/wordpress.com.rb', line 11

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