Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Scott Chacon February 11, 2009
file 37 lines (29 sloc) 0.985 kb
1 2 3 4 5 6 7 8 9 10 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
require 'rexml/document'
require 'date'
require 'fileutils'

include REXML # so that we don't have to prefix everything with REXML::...

file = File.new( "wordpress.2009-02-11.xml" )
doc = REXML::Document.new file

entries = []

doc.elements.each("//item") do |element|
  title = element.get_text("title")
  post_name = element.get_text("wp:post_name")
  datestr = "#{element.get_text("pubDate")}"
  d = DateTime.parse(datestr).strftime("%Y-%m-%d")
  desc = element.get_text("content:encoded")
  category = element.get_text("category")
  category = "Blogging" if category == "" or category.nil?
  puts category
  puts d
  puts title
  puts post_name
  dir = "_posts/#{category}/"
  FileUtils.mkdir(dir) if !File.exists?(dir)
  filename = dir + "#{d}-#{post_name}.html"
  post = "---\n"
  post += "layout: post\n"
  post += "title: #{title}\n"
  post += "---\n"
  post += desc.to_s.gsub("’", "'").gsub("\n\n", "<br/>\n")
  File.open(filename, 'w') { |f| f.write(post) }
end



Something went wrong with that request. Please try again.