Permalink
Browse files

Added handling for Tumblr missing image extensions.

  • Loading branch information...
1 parent c26bd30 commit f2502dfab2da77f916731edcc4ac22022aeabf4b @stephenmcd stephenmcd committed Dec 30, 2011
Showing with 9 additions and 6 deletions.
  1. +9 −6 lib/jekyll/migrators/tumblr.rb
@@ -59,7 +59,10 @@ def self.post_to_hash(post, format)
title = post["photo-caption"]
max_size = post.keys.map{ |k| k.gsub("photo-url-", "").to_i }.max
url = post["photo-url"] || post["photo-url-#{max_size}"]
- content = "<img src=\"#{save_file(url)}\"/>"
+ ext = "." + post[post.keys.select { |k|
+ k =~ /^photo-url-/ && post[k].split("/").last =~ /\./
+ }.first].split(".").last
+ content = "<img src=\"#{save_file(url, ext)}\"/>"
unless post["photo-link-url"].nil?
content = "<a href=\"#{post["photo-link-url"]}\">#{content}</a>"
end
@@ -178,13 +181,13 @@ def self.add_syntax_highlights(content)
lines.join("\n")
end
- def self.save_file(url)
+ def self.save_file(url, ext)
if @grab_images
+ path = "tumblr_files/#{url.split('/').last}"
+ path += ext unless path =~ /#{ext}$/
FileUtils.mkdir_p "tumblr_files"
- File.open("tumblr_files/#{url.split('/').last}", "w") do |f|
- f.write(open(url).read)
- end
- url = "/tumblr_files/#{url.split('/').last}"
+ File.open(path, "w") { |f| f.write(open(url).read) }
+ url = "/" + path
end
url
end

0 comments on commit f2502df

Please sign in to comment.