FIX: use normal logo in published pages if small not available.

FIX: use normal logo in published pages if small not available.

It was returning an error if small logo is not available. If both logos are not available then it will be hidden now.

diff --git a/app/controllers/published_pages_controller.rb b/app/controllers/published_pages_controller.rb
index 4ce1177..a51776a 100644
--- a/app/controllers/published_pages_controller.rb
+++ b/app/controllers/published_pages_controller.rb
@@ -31,7 +31,7 @@ class PublishedPagesController < ApplicationController
 
     @topic = pp.topic
     @canonical_url = @topic.url
-    @logo = SiteSetting.logo_small
+    @logo = SiteSetting.logo_small || SiteSetting.logo
     @site_url = Discourse.base_url
     @border_color = "#" + ColorScheme.base_colors["tertiary"]
 
diff --git a/app/views/published_pages/show.html.erb b/app/views/published_pages/show.html.erb
index 0f84c9c..7cf3b07 100644
--- a/app/views/published_pages/show.html.erb
+++ b/app/views/published_pages/show.html.erb
@@ -2,9 +2,11 @@
 
 <div class="published-page-header">
     <div class="published-page-header-wrapper">
-      <a href="<%= @site_url %>">
-        <img class="published-page-logo" src="<%=@logo.url%>"/>
-      </a>
+      <%- if @logo.present? %>
+        <a href="<%= @site_url %>">
+          <img class="published-page-logo" src="<%=@logo.url%>"/>
+        </a>
+      <%- end -%>
       <h1 class="published-page-title"><%= @topic.title %></h1>
     </div>
   </div>
@@ -23,4 +25,4 @@
       <%= @topic.first_post.cooked.html_safe %>
     </div>
   <%- end -%>
-</div>
\ No newline at end of file
+</div>
diff --git a/spec/requests/published_pages_controller_spec.rb b/spec/requests/published_pages_controller_spec.rb
index d5fed80..5aa1470 100644
--- a/spec/requests/published_pages_controller_spec.rb
+++ b/spec/requests/published_pages_controller_spec.rb
@@ -98,6 +98,16 @@ RSpec.describe PublishedPagesController do
           expect(response.status).to eq(200)
         end
 
+        it "works even if image logos are not available" do
+          SiteSetting.logo_small = nil
+          get published_page.path
+          expect(response.body).to include("<img class=\"published-page-logo\" src=\"#{SiteSetting.logo.url}\"/>")
+
+          SiteSetting.logo = nil
+          get published_page.path
+          expect(response.body).not_to include("published-page-logo")
+        end
+
         it "defines correct css classes on body" do
           get published_page.path
           expect(response.body).to include("<body class=\"published-page #{published_page.slug} topic-#{published_page.topic_id} recipes uncategorized\">")

GitHub sha: 6b818fb8

1 Like

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

https://meta.discourse.org/t/error-500-using-page-publication/161893/7