From 4863c4517ae1056dbb655f8768b2a3b032d5f5a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Wed, 6 Nov 2013 16:59:11 +0100 Subject: [PATCH] use absolute url for assets too --- lib/cooked_post_processor.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb index 466a84ed471..c794b793a69 100644 --- a/lib/cooked_post_processor.rb +++ b/lib/cooked_post_processor.rb @@ -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