Added handling for Tumblr missing image extensions.
This commit is contained in:
parent
c26bd30318
commit
f2502dfab2
|
@ -59,7 +59,10 @@ module Jekyll
|
||||||
title = post["photo-caption"]
|
title = post["photo-caption"]
|
||||||
max_size = post.keys.map{ |k| k.gsub("photo-url-", "").to_i }.max
|
max_size = post.keys.map{ |k| k.gsub("photo-url-", "").to_i }.max
|
||||||
url = post["photo-url"] || post["photo-url-#{max_size}"]
|
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?
|
unless post["photo-link-url"].nil?
|
||||||
content = "<a href=\"#{post["photo-link-url"]}\">#{content}</a>"
|
content = "<a href=\"#{post["photo-link-url"]}\">#{content}</a>"
|
||||||
end
|
end
|
||||||
|
@ -178,13 +181,13 @@ module Jekyll
|
||||||
lines.join("\n")
|
lines.join("\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.save_file(url)
|
def self.save_file(url, ext)
|
||||||
if @grab_images
|
if @grab_images
|
||||||
|
path = "tumblr_files/#{url.split('/').last}"
|
||||||
|
path += ext unless path =~ /#{ext}$/
|
||||||
FileUtils.mkdir_p "tumblr_files"
|
FileUtils.mkdir_p "tumblr_files"
|
||||||
File.open("tumblr_files/#{url.split('/').last}", "w") do |f|
|
File.open(path, "w") { |f| f.write(open(url).read) }
|
||||||
f.write(open(url).read)
|
url = "/" + path
|
||||||
end
|
|
||||||
url = "/tumblr_files/#{url.split('/').last}"
|
|
||||||
end
|
end
|
||||||
url
|
url
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue