diff --git a/app/lib/html_css_to_image.rb b/app/lib/html_css_to_image.rb
index d9da9bbef..5561ccdf7 100644
--- a/app/lib/html_css_to_image.rb
+++ b/app/lib/html_css_to_image.rb
@@ -2,8 +2,6 @@ module HtmlCssToImage
AUTH = { username: ApplicationConfig["HCTI_API_USER_ID"],
password: ApplicationConfig["HCTI_API_KEY"] }.freeze
- FALLBACK_IMAGE = "https://thepracticaldev.s3.amazonaws.com/i/g355ol6qsrg0j2mhngz9.png".freeze
-
CACHE_EXPIRATION = 6.weeks
def self.url(html:, css: nil, google_fonts: nil)
@@ -11,7 +9,7 @@ module HtmlCssToImage
body: { html: html, css: css, google_fonts: google_fonts },
basic_auth: AUTH)
- image["url"] || FALLBACK_IMAGE
+ image["url"] || fallback_image
end
def self.fetch_url(html:, css: nil, google_fonts: nil)
@@ -21,10 +19,14 @@ module HtmlCssToImage
return cached_url if cached_url.present?
image_url = url(html: html, css: css, google_fonts: google_fonts)
- unless image_url == FALLBACK_IMAGE
+ unless image_url == fallback_image
Rails.cache.write(cache_key, image_url, expires_in: CACHE_EXPIRATION)
end
image_url
end
+
+ def self.fallback_image
+ SiteConfig.main_social_image.to_s
+ end
end
diff --git a/app/views/pages/show.html.erb b/app/views/pages/show.html.erb
index e8d818cf1..5defd7507 100644
--- a/app/views/pages/show.html.erb
+++ b/app/views/pages/show.html.erb
@@ -7,7 +7,7 @@
- " />
+
@@ -15,7 +15,7 @@
">
- ">
+
<% end %>
<% if @page.template == "contained" %>
diff --git a/spec/lib/html_css_to_image_spec.rb b/spec/lib/html_css_to_image_spec.rb
index 87b1e14fb..5037449df 100644
--- a/spec/lib/html_css_to_image_spec.rb
+++ b/spec/lib/html_css_to_image_spec.rb
@@ -17,12 +17,13 @@ RSpec.describe HtmlCssToImage, type: :lib do
body: '{ "error": "Plan limit exceeded" }',
headers: { "Content-Type" => "application/json" })
- expect(described_class.url(html: "test")).to eq described_class::FALLBACK_IMAGE
+ expect(described_class.url(html: "test")).to eq described_class.fallback_image
end
end
describe ".fetch_url" do
before do
+ allow(SiteConfig).to receive(:main_social_image).and_return("https://testimage.com/image.png")
allow(Rails.cache).to receive(:write)
allow(Rails.cache).to receive(:read)
end
@@ -57,7 +58,7 @@ RSpec.describe HtmlCssToImage, type: :lib do
body: '{ "error": "Plan limit exceeded" }',
headers: { "Content-Type" => "application/json" })
- expect(described_class.fetch_url(html: "test")).to eq described_class::FALLBACK_IMAGE
+ expect(described_class.fetch_url(html: "test")).to eq described_class.fallback_image
expect(Rails.cache).not_to have_received(:write)
end
end