use absolute url for assets too

This commit is contained in:
Régis Hanol 2013-11-06 16:59:11 +01:00
parent e5202b19c0
commit 4863c4517a
1 changed files with 7 additions and 7 deletions

View File

@ -197,20 +197,20 @@ class CookedPostProcessor
def optimize_urls
@doc.search("a").each do |a|
href = a["href"].to_s
if Discourse.store.has_been_uploaded?(href)
a["href"] = schemaless relative_to_absolute(href)
end
a["href"] = schemaless absolute(href) if is_local(href)
end
@doc.search("img").each do |img|
src = img["src"].to_s
if Discourse.store.has_been_uploaded?(src)
img["src"] = schemaless relative_to_absolute(src)
end
img["src"] = schemaless absolute(src) if is_local(src)
end
end
def relative_to_absolute(url)
def is_local(url)
Discourse.store.has_been_uploaded?(url) || url =~ /^\/assets\//
end
def absolute(url)
url =~ /^\/[^\/]/ ? (Discourse.asset_host || Discourse.base_url_no_prefix) + url : url
end