FIX: use absolute url for `/images/example.png` links FEATURE: fallback to logo_url as last resort for opengraph image url

FIX: use absolute url for /images/example.png links FEATURE: fallback to logo_url as last resort for opengraph image url

diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 8ca6e21..810cfe1 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -222,6 +222,8 @@ module ApplicationHelper
       opts[:image] = opengraph_image_url.present? ? opengraph_image_url : twitter_summary_large_image_url
     elsif opts[:image].blank? && SiteSetting.site_apple_touch_icon_url.present?
       opts[:image] = SiteSetting.site_apple_touch_icon_url
+    elsif opts[:image].blank? && SiteSetting.logo_url.present?
+      opts[:image] = SiteSetting.logo_url
     end
 
     # Use the correct scheme for opengraph/twitter image
@@ -478,6 +480,8 @@ module ApplicationHelper
       absolute_url = "#{uri.scheme}:#{link}"
     elsif link.start_with?("/uploads/")
       absolute_url = "#{Discourse.base_url}#{link}"
+    elsif link.start_with?("/images/")
+      absolute_url = "#{Discourse.base_url}#{link}"
     elsif GlobalSetting.relative_url_root && link.start_with?(GlobalSetting.relative_url_root)
       absolute_url = "#{Discourse.base_url_no_prefix}#{link}"
     end
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb
index 5186ddd..23bb277 100644
--- a/spec/helpers/application_helper_spec.rb
+++ b/spec/helpers/application_helper_spec.rb
@@ -229,4 +229,22 @@ describe ApplicationHelper do
       expect(helper.preloaded_json).to eq(%{{"test":"[\\"\\u003c \uFFFD\\"]"}})
     end
   end
+
+  describe 'crawlable_meta_data' do
+    context "opengraph image" do
+      it 'returns default_opengraph_image_url' do
+        SiteSetting.default_opengraph_image_url = "/images/og-image.png"
+        expect(helper.crawlable_meta_data).to include("/images/og-image.png")
+      end
+
+      it 'returns apple_touch_icon_url if default_opengraph_image_url is blank' do
+        expect(helper.crawlable_meta_data).to include("/images/default-apple-touch-icon.png")
+      end
+
+      it 'returns logo_url if apple_touch_icon_url is blank' do
+        SiteSetting.apple_touch_icon_url = ""
+        expect(helper.crawlable_meta_data).to include("/images/d-logo-sketch.png")
+      end
+    end
+  end
 end

GitHub sha: f83533e1

This commit has been mentioned on Discourse Meta. There might be relevant details there: