Skip to content

A platform for community discussion. Free, open, simple.

FIX: If a tag has a description, use it for the meta description. (#31689)

Gary Pendergaste77e5bd3cc69
diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb
index fbf0953d991..3f309e38478 100644
--- a/app/controllers/tags_controller.rb
+++ b/app/controllers/tags_controller.rb
@@ -162,8 +162,8 @@ class TagsController < ::ApplicationController
@list.more_topics_url = construct_url_with(:next, list_opts)
@list.prev_topics_url = construct_url_with(:prev, list_opts)
@rss = "tag"
- @description_meta = I18n.t("rss_by_tag", tag: tag_params.join(" & "))
- @title = @description_meta
+ @title = I18n.t("rss_by_tag", tag: tag_params.join(" & "))
+ @description_meta = Tag.where(name: @tag_id).pick(:description) || @title
canonical_params = params.slice(:category_slug_path_with_id, :tag_id)
canonical_method = url_method(canonical_params)
diff --git a/spec/requests/tags_controller_spec.rb b/spec/requests/tags_controller_spec.rb
index fb23c0e4c44..156de764f0b 100644
--- a/spec/requests/tags_controller_spec.rb
+++ b/spec/requests/tags_controller_spec.rb
@@ -465,6 +465,27 @@ RSpec.describe TagsController do
)
end
+ it "puts the tag description in the meta description" do
+ described_tag = Fabricate(:tag, name: "test2", description: "This is a description")
+ get "/tag/#{described_tag.name}"
+
+ expect(response.status).to eq(200)
+
+ expect(response.body).to include(
+ "<meta name=\"description\" content=\"#{described_tag.description}\"",
+ )
+ end
+
+ it "has a default description for tags without a description" do
+ get "/tag/test"
+
+ expect(response.status).to eq(200)
+
+ expect(response.body).to include(
+ "<meta name=\"description\" content=\"Topics tagged #{tag.name}\"",
+ )
+ end
+
it "handles special tag 'none'" do
SiteSetting.pm_tags_allowed_for_groups = "1|2|3"