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