iamruinous / mephisto-to-wxr

export a mephisto blog to WordPress eXtended RSS (WXR)

This URL has Read+Write access

Jade Meskill (author)
Tue Jan 13 09:38:10 -0800 2009
mephisto-to-wxr / wxr.rake
100644 66 lines (61 sloc) 2.311 kb
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
55
56
57
58
59
60
61
62
63
64
65
66
namespace :wxr do
 
task :export => :environment do
  require 'uuidtools'
  if ENV['MEPHISTO_SITE']
    site = Site.find_by_host(ENV['MEPHISTO_SITE'])
  else
    site = Site.find(:first)
  end
  
  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 site.title
      xml.link "http://#{site.host}"
      xml.language "en-us"
      xml.ttl "40"
      xml.description site.subtitle
  
      site.articles.each do |a|
        a.published_at ||= a.created_at
          xml.item do
            xml.title a.title
            xml.content(:encoded) { |x| x << a.body_html }
            xml.pubDate a.published_at.rfc2822
            xml.guid "urn:uuid:#{UUID.random_create}", "isPermaLink" => "false"
            author = a.user.login
            xml.author author
            xml.dc :creator, author
            a.tags.each do |tag|
              xml.tag tag
            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.author_email
                xml.wp :comment_author_url, comment.author_url
                xml.wp :comment_author_IP, comment.author_ip
                xml.wp :comment_date, comment.published_at.strftime("%Y-%m-%d %H:%M:%S")
                xml.wp(:comment_content) { |x| x << comment.body_html }
                xml.wp :comment_approved, '1'
                xml.wp :comment_parent, '0'
              end
            end
         end
      end
    end
  end
end
 
end