From f2502dfab2da77f916731edcc4ac22022aeabf4b Mon Sep 17 00:00:00 2001 From: Stephen McDonald Date: Fri, 30 Dec 2011 23:25:09 +1100 Subject: [PATCH] Added handling for Tumblr missing image extensions. --- lib/jekyll/migrators/tumblr.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/jekyll/migrators/tumblr.rb b/lib/jekyll/migrators/tumblr.rb index e2758ba8..367a83c9 100644 --- a/lib/jekyll/migrators/tumblr.rb +++ b/lib/jekyll/migrators/tumblr.rb @@ -59,7 +59,10 @@ module Jekyll 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 = "" + ext = "." + post[post.keys.select { |k| + k =~ /^photo-url-/ && post[k].split("/").last =~ /\./ + }.first].split(".").last + content = "" unless post["photo-link-url"].nil? content = "#{content}" end @@ -178,13 +181,13 @@ module Jekyll 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