FIX: CDN doesn't work with S3

This commit is contained in:
Régis Hanol
2013-07-16 22:16:33 +02:00
parent 7c9bd8e8c9
commit 3136638b4b
3 changed files with 10 additions and 3 deletions

View File

@@ -166,17 +166,18 @@ module PrettyText
return html unless url
image = /\.(jpg|jpeg|gif|png|tiff|tif|bmp)$/
relative = /^\/[^\/]/
doc = Nokogiri::HTML.fragment(html)
doc.css("a").each do |l|
href = l["href"].to_s
l["href"] = url + href if href[0] == '/' && href =~ image
l["href"] = url + href if href =~ relative && href =~ image
end
doc.css("img").each do |l|
src = l["src"].to_s
l["src"] = url + src if src[0] == '/'
l["src"] = url + src if src =~ relative
end
doc.to_s