mirror of
https://github.com/discourse/discourse.git
synced 2025-01-31 06:09:30 +08:00
use absolute url for assets too
This commit is contained in:
parent
e5202b19c0
commit
4863c4517a
|
@ -197,20 +197,20 @@ class CookedPostProcessor
|
||||||
def optimize_urls
|
def optimize_urls
|
||||||
@doc.search("a").each do |a|
|
@doc.search("a").each do |a|
|
||||||
href = a["href"].to_s
|
href = a["href"].to_s
|
||||||
if Discourse.store.has_been_uploaded?(href)
|
a["href"] = schemaless absolute(href) if is_local(href)
|
||||||
a["href"] = schemaless relative_to_absolute(href)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc.search("img").each do |img|
|
@doc.search("img").each do |img|
|
||||||
src = img["src"].to_s
|
src = img["src"].to_s
|
||||||
if Discourse.store.has_been_uploaded?(src)
|
img["src"] = schemaless absolute(src) if is_local(src)
|
||||||
img["src"] = schemaless relative_to_absolute(src)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
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
|
url =~ /^\/[^\/]/ ? (Discourse.asset_host || Discourse.base_url_no_prefix) + url : url
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user