From 42c405a8200f9e481bcd64a18beabed9a8dea8d4 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Wed, 17 Oct 2018 13:49:32 +0530 Subject: [PATCH] FIX: use topic summary for meta description if topic excerpt is blank --- app/controllers/topics_controller.rb | 2 +- spec/requests/topics_controller_spec.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index a647d466f79..fd93edbb7bd 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -845,7 +845,7 @@ class TopicsController < ApplicationController respond_to do |format| format.html do - @description_meta = @topic_view.topic.excerpt || @topic_view.summary + @description_meta = @topic_view.topic.excerpt.present? ? @topic_view.topic.excerpt : @topic_view.summary store_preloaded("topic_#{@topic_view.topic.id}", MultiJson.dump(topic_view_serializer)) render :show end diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb index 94c9a010055..c15c9770eb1 100644 --- a/spec/requests/topics_controller_spec.rb +++ b/spec/requests/topics_controller_spec.rb @@ -1407,6 +1407,17 @@ RSpec.describe TopicsController do expect(response.headers['Discourse-Readonly']).to eq('true') end end + + describe "image only topic" do + it "uses image alt tag for meta description" do + post = Fabricate(:post, raw: "![image_description|690x405](upload://sdtr5O5xaxf0iEOxICxL36YRj86.png)") + + get post.topic.url + + body = response.body + expect(body).to have_tag(:meta, with: { name: 'description', content: '[image_description]' }) + end + end end describe '#post_ids' do