From fa9806c31c4c2688ac5f7cc4d6902da599f649bf Mon Sep 17 00:00:00 2001 From: Wesley Moore Date: Tue, 17 Nov 2009 13:18:17 +1100 Subject: [PATCH] Start an importer for a Wordpress XML export --- importer/import.rb | 7 +++++++ importer/wordpress.rb | 46 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 importer/import.rb create mode 100644 importer/wordpress.rb diff --git a/importer/import.rb b/importer/import.rb new file mode 100644 index 0000000..121c5bd --- /dev/null +++ b/importer/import.rb @@ -0,0 +1,7 @@ +require 'rubygems' + +require 'wordpress' + +i = Importer::Wordpress.new('wezm.net.2009-11-17.xml') + +i.run diff --git a/importer/wordpress.rb b/importer/wordpress.rb new file mode 100644 index 0000000..abf8fe1 --- /dev/null +++ b/importer/wordpress.rb @@ -0,0 +1,46 @@ +require 'nokogiri' +require 'nanoc3' + +module Importer + + class Wordpress + + def initialize(wordpress_export_path) + @export_file = File.open(wordpress_export_path) + @export = Nokogiri::XML(@export_file) + end + + def run + # Loop over each post + @export.xpath('//rss/channel/item').each do |item| + item_type = item.xpath('wp:post_type').first.text + case item_type + when 'post' + process_post(item) + when 'page' + process_page(item) + when 'attachment' + process_attachment(item) + else + puts "Unknown post type: #{item_type}" + end + end + end + + protected + + def process_post(post) + puts "Processing post: #{post.css('title').first.text}" + end + + def process_page(page) + puts "Processing page: #{page.css('title').first.text}" + end + + def process_attachment(attachment) + puts "Processing attachment" + end + + end + +end