diff --git a/History.txt b/History.txt index bbc08d74d80..fb2bc97cb38 100644 --- a/History.txt +++ b/History.txt @@ -9,6 +9,7 @@ * Fixes for Wordpress importer (#274, #252, #271) * Better error message for invalid post date (#291) * Print formatted fatal exceptions to stdout on build failure + * Add Tumblr importer (#323) * Bug Fixes * Secure additional path exploits diff --git a/bin/jekyll b/bin/jekyll index c025a62341a..ffe089bdbe5 100755 --- a/bin/jekyll +++ b/bin/jekyll @@ -164,6 +164,7 @@ if ARGV.size > 0 :mephisto => 'Mephisto', :mt => 'MT', :textpattern => 'TextPattern', + :tumblr => 'Tumblr', :typo => 'Typo' } diff --git a/lib/jekyll/migrators/tumblr.rb b/lib/jekyll/migrators/tumblr.rb index 0f7d539f945..0345b4a9dc8 100644 --- a/lib/jekyll/migrators/tumblr.rb +++ b/lib/jekyll/migrators/tumblr.rb @@ -8,7 +8,6 @@ module Jekyll module Tumblr - def self.process(url, grab_images = false) current_page = 0 @@ -17,7 +16,7 @@ def self.process(url, grab_images = false) doc = Nokogiri::HTML(Iconv.conv("utf-8", f.charset, f.readlines.join("\n"))) puts "Page: #{current_page + 1} - Posts: #{(doc/:tumblr/:posts/:post).size}" - + FileUtils.mkdir_p "_posts/tumblr" (doc/:tumblr/:posts/:post).each do |post| @@ -41,19 +40,19 @@ def self.process(url, grab_images = false) 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-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) + "
" @@ -61,23 +60,23 @@ def self.process(url, grab_images = false) elsif post['type'] == "conversation" title = post.at("conversation-title").inner_html unless post.at("conversation-title") == nil content = "
" - + (post/:conversation/:line).each do |line| content << "
" + line['label'] + "
" + line.inner_html + "
" unless line['label'] == nil || line == nil end - + content << "
" - elsif post['type'] == "video" + 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 end # End post types name = "#{Date.parse(post['date']).to_s}-#{post['id'].downcase.gsub(/[^a-z0-9]/, '-')}.html" - + if title != nil || content != nil && name != nil File.open("_posts/tumblr/#{name}", "w") do |f| - + f.puts <<-HEADER --- layout: post @@ -106,16 +105,15 @@ def self.process(url, grab_images = false) def self.save_file(url, grab_image = false) unless grab_image == false FileUtils.mkdir_p "tumblr_files" - + File.open("tumblr_files/#{url.split('/').last}", "w") do |f| f.write(open(url).read) end - + return "/tumblr_files/#{url.split('/').last}" else return url end end - end end