Skip to content

Commit

Permalink
Clean up Tumblr importer and update History.
Browse files Browse the repository at this point in the history
  • Loading branch information
mojombo committed May 9, 2011
1 parent 9cc9c23 commit b86bc97
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
1 change: 1 addition & 0 deletions History.txt
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions bin/jekyll
Expand Up @@ -164,6 +164,7 @@ if ARGV.size > 0
:mephisto => 'Mephisto',
:mt => 'MT',
:textpattern => 'TextPattern',
:tumblr => 'Tumblr',
:typo => 'Typo'
}

Expand Down
24 changes: 11 additions & 13 deletions lib/jekyll/migrators/tumblr.rb
Expand Up @@ -8,7 +8,6 @@

module Jekyll
module Tumblr

def self.process(url, grab_images = false)
current_page = 0

Expand All @@ -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|
Expand All @@ -41,43 +40,43 @@ def self.process(url, grab_images = false)
content << "<br/>" + 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 = "<a href=\"#{post.at("photo-link-url").inner_html}\"><img src=\"#{save_file((post/"photo-url")[1].inner_html, grab_images)}\"/></a>"
else
content = "<img src=\"#{save_file((post/"photo-url")[1].inner_html, grab_images)}\"/>"
end

if post.at("photo-caption") != nil
content << "<br/>" 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 = "<blockquote>" + CGI::unescapeHTML(post.at("quote-text").inner_html) + "</blockquote>"
content << "&#8212;" + 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 = "<section><dialog>"

(post/:conversation/:line).each do |line|
content << "<dt>" + line['label'] + "</dt><dd>" + line.inner_html + "</dd>" unless line['label'] == nil || line == nil
end

content << "<section><dialog>"
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
Expand Down Expand Up @@ -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

0 comments on commit b86bc97

Please sign in to comment.