public
Created

Exporting Typo to Disqus

  • Download Gist
export_typo.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
# 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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.