Skip to content

Instantly share code, notes, and snippets.

@wsargent
Created February 16, 2012 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wsargent/1847244 to your computer and use it in GitHub Desktop.
Save wsargent/1847244 to your computer and use it in GitHub Desktop.
Exporting Typo to Disqus
# Require nokogiri in Gemfile here
site_link = "http://tersesystems.com/"
site_name = "Terse Systems"
builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
xml.rss('version' => "2.0",
'xmlns:content' => "http://purl.org/rss/1.0/modules/content/",
'xmlns:dsq' => "http://www.disqus.com/",
'xmlns:dc' => "http://purl.org/dc/elements/1.1/",
'xmlns:wp' => "http://wordpress.org/export/1.0/") do |xml|
xml.channel do |channel|
channel.title site_name
channel.link site_link
articles = Article.find(:all)
articles.each do |a|
channel.item do |item|
item.title a.title
item.link a.permalink
item['content'].encoded do
item.cdata("Hello world")
end
item['dsq'].thread_identifier "#{site_link}#{a.published_at.strftime("%Y/%m/%d")}/#{a.permalink}"
item['wp'].post_date_gmt a.published_at.strftime("%Y-%m-%d %H:%M:%S")
item['wp'].comment_status 'closed'
a.comments.each { |comment_data|
item['wp'].comment do |comment|
comment['wp'].comment_id comment_data.id
comment['wp'].comment_author comment_data.author
# If you have empty XML elements then the import fails, so don't render empty strings
if (comment_data.email)
comment['wp'].comment_author_email comment_data.email
end
if (comment_data.url)
comment['wp'].comment_author_url comment_data.url
end
if (comment_data.ip)
comment['wp'].comment_author_IP comment_data.ip
end
comment['wp'].comment_date_gmt comment_data.published_at.strftime("%Y-%m-%d %H:%M:%S")
comment['wp'].comment_content do
comment.cdata comment_data.body
end
comment['wp'].comment_approved '1'
comment['wp'].comment_parent '0'
end
}
end
end
end
end
end
puts builder.to_xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment