Created
February 23, 2012 16:35
-
-
Save ajokela/1893649 to your computer and use it in GitHub Desktop.
Typo Blog to Wordpress - RSS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require File.dirname(__FILE__) + '/../config/boot' | |
require 'environment' | |
require 'application' | |
articles = Article.find(:all) | |
xml = Builder::XmlMarkup.new(:target => STDOUT, :indent => 2) | |
xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" | |
xml.rss 'version' => "2.0", | |
'xmlns:content' => "http://purl.org/rss/1.0/modules/content/", | |
'xmlns:wfw' => "http://wellformedweb.org/CommentAPI/", | |
'xmlns:dc' => "http://purl.org/dc/elements/1.1/", | |
'xmlns:wp' => "http://wordpress.org/export/1.0/" do | |
xml.channel do | |
xml.title "Blog Title" | |
xml.link "http://www.blogurl.com/" | |
xml.language "en-us" | |
xml.ttl "40" | |
xml.description "Blog Description" | |
articles.each do |a| | |
xml.item do | |
xml.title a.title | |
xml.content(:encoded) { |x| x << a.html } | |
xml.pubDate a.published_at.rfc2822 | |
xml.guid "urn:uuid:{a.guid}", "isPermaLink" => "false" | |
author = a.user.name rescue a.author | |
xml.author author | |
xml.dc :creator, author | |
for category in a.categories | |
xml.category category.name | |
end | |
for tag in a.tags | |
xml.category tag.display_name | |
end | |
xml.wp :post_id, a.id | |
xml.wp :post_date, a.published_at.strftime("%Y-%m-%d %H:%M:%S") | |
xml.wp :comment_status, 'closed' | |
xml.wp :ping_status, 'closed' | |
xml.wp :post_name, a.permalink | |
xml.wp :status, 'publish' | |
xml.wp :post_parent, '0' | |
xml.wp :post_type, 'post' | |
for comment in a.comments | |
xml.wp(:comment) do | |
xml.wp :comment_id, comment.id | |
xml.wp :comment_author, comment.author | |
xml.wp :comment_author_email, comment.email | |
xml.wp :comment_author_url, comment.url | |
xml.wp :comment_author_IP, comment.ip | |
xml.wp :comment_date, comment.published_at.strftime("%Y-%m-%d %H:%M:%S") | |
xml.wp(:comment_content) { |x| x << comment.body } | |
xml.wp :comment_approved, '1' | |
xml.wp :comment_parent, '0' | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment