1
0
Fork 1
mirror of https://github.com/wezm/wezm.net.git synced 2024-12-22 20:19:54 +00:00

Start an importer for a Wordpress XML export

This commit is contained in:
Wesley Moore 2009-11-17 13:18:17 +11:00
parent aaef0f322f
commit fa9806c31c
2 changed files with 53 additions and 0 deletions

7
importer/import.rb Normal file
View file

@ -0,0 +1,7 @@
require 'rubygems'
require 'wordpress'
i = Importer::Wordpress.new('wezm.net.2009-11-17.xml')
i.run

46
importer/wordpress.rb Normal file
View file

@ -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