diff --git a/lib/jekyll/migrators/tumblr.rb b/lib/jekyll/migrators/tumblr.rb
index 332c5fb0..3fd15642 100644
--- a/lib/jekyll/migrators/tumblr.rb
+++ b/lib/jekyll/migrators/tumblr.rb
@@ -1,10 +1,8 @@
require 'rubygems'
-require 'nokogiri'
require 'open-uri'
require 'fileutils'
-require 'cgi'
-require 'iconv'
require 'date'
+require 'json'
module Jekyll
module Tumblr
@@ -12,97 +10,67 @@ module Jekyll
current_page = 0
while true
- f = open(url + "/api/read?num=50&start=#{current_page * 50}")
- doc = Nokogiri::HTML(Iconv.conv("utf-8", f.charset, f.readlines.join("\n")))
-
- puts "Page: #{current_page + 1} - Posts: #{(doc/:tumblr/:posts/:post).size}"
+ f = open(url + "/api/read/json/?num=50&start=#{current_page * 50}")
+ # [21...-2] strips Tumblr's Javascript/JSONP start/end chars
+ json = f.readlines.join("\n")[21...-2]
+ blog = JSON.parse(json)
+ puts "Page: #{current_page + 1} - Posts: #{blog["posts"].size}"
FileUtils.mkdir_p "_posts/tumblr"
- (doc/:tumblr/:posts/:post).each do |post|
- title = ""
- content = nil
- name = nil
+ blog["posts"].each do |post|
- if post['type'] == "regular"
- title_element = post.at("regular-title")
- title = title_element.inner_text unless title_element == nil
- content = CGI::unescapeHTML post.at("regular-body").inner_html unless post.at("regular-body") == nil
- elsif post['type'] == "link"
- title = post.at("link-text").inner_html unless post.at("link-text") == nil
-
- if post.at("link-text") != nil
- content = "#{post.at("link-text").inner_html}"
- else
- content = "#{post.at("link-url").inner_html}"
- end
-
- content << "
" + CGI::unescapeHTML(post.at("link-description").inner_html) unless post.at("link-description") == nil
- elsif post['type'] == "photo"
- content = ""
-
- if post.at("photo-link-url") != nil
- content = ""
- else
- content = "
"
- end
-
- if post.at("photo-caption") != nil
- content << "
" unless content == nil
- content << CGI::unescapeHTML(post.at("photo-caption").inner_html)
- end
- elsif post['type'] == "audio"
- content = CGI::unescapeHTML(post.at("audio-player").inner_html)
- content << CGI::unescapeHTML(post.at("audio-caption").inner_html) unless post.at("audio-caption") == nil
- elsif post['type'] == "quote"
- content = "
" + CGI::unescapeHTML(post.at("quote-text").inner_html) + "" - content << "—" + CGI::unescapeHTML(post.at("quote-source").inner_html) unless post.at("quote-source") == nil - elsif post['type'] == "conversation" - title = post.at("conversation-title").inner_html unless post.at("conversation-title") == nil - content = "" - elsif post['type'] == "video" - title = post.at("video-title").inner_html unless post.at("video-title") == nil - content = CGI::unescapeHTML(post.at("video-player").inner_html) - content << CGI::unescapeHTML(post.at("video-caption").inner_html) unless post.at("video-caption") == nil + case post['type'] + when "regular" + title = post["regular-title"] + content = post["regular-body"] + when "link" + title = post["link-text"] || post["link-url"] + content = "#{title}" + content << "
#{post["quote-text"]}" + content << "—" + post["quote-source"] unless post["quote-source"].nil? + when "conversation" + title = post["conversation-title"] + content = "" + when "video" + title = post["video-title"] + content = post["video-player"] + content << "