Skip to content

Commit

Permalink
The Wordpress.com migrator now works and gathers categories as tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
elia committed Jan 27, 2011
1 parent 13df722 commit f68bbcb
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions lib/jekyll/migrators/wordpress.com.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'rubygems'
require 'hpricot'
require 'fileutils'
require 'yaml'

# This importer takes a wordpress.xml file,
# which can be exported from your
Expand All @@ -16,16 +17,20 @@ def self.process(filename = "wordpress.xml")

(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"

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")}-#{title.downcase.gsub(/\W+/, '-')}.html"
header = {
'layout' => 'post',
'title' => title,
'tags' => tags
}

File.mkdir("_posts") unless File.directory?("_posts")
File.open("_posts/#{name}", "w") do |f|
f.puts <<-HEADER
---
layout: post
title: #{title}
---
HEADER
f.puts header.to_yaml
f.puts '---'
f.puts
f.puts item.at('content:encoded').inner_text
end

Expand Down

0 comments on commit f68bbcb

Please sign in to comment.