Skip to content

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

FIX: Shorten subcategory hashtags when category card UC enabled (#44805)

Martin Brennandcdd8f5a5225
diff --git a/app/services/category_hashtag_data_source.rb b/app/services/category_hashtag_data_source.rb
index f17e8f92c9a..9bfc3fd4fcb 100644
--- a/app/services/category_hashtag_data_source.rb
+++ b/app/services/category_hashtag_data_source.rb
@@ -24,7 +24,7 @@ class CategoryHashtagDataSource
HashtagAutocompleteService::HashtagItem.new.tap do |item|
item.text =
(
- if category.parent_category
+ if category.parent_category && !SiteSetting.enable_category_hashtag_cards
"#{category.parent_category.name} > #{category.name}"
else
category.name
diff --git a/spec/lib/pretty_text_spec.rb b/spec/lib/pretty_text_spec.rb
index 4255cffdea6..abac8c650d5 100644
--- a/spec/lib/pretty_text_spec.rb
+++ b/spec/lib/pretty_text_spec.rb
@@ -2028,6 +2028,28 @@ RSpec.describe PrettyText do
end
end
+ it "uses concise subcategory hashtag text without losing the full reference" do
+ SiteSetting.enable_category_hashtag_cards = true
+ parent_category = Fabricate(:category, name: "Silly Land", slug: "fun")
+ category =
+ Fabricate(:category, name: "Random", slug: "random", parent_category: parent_category)
+
+ cooked = PrettyText.cook("#fun:random")
+
+ expect(cooked).to have_tag(
+ "a",
+ text: "Random",
+ with: {
+ class: "hashtag-cooked",
+ href: category.url,
+ "data-type": "category",
+ "data-slug": "random",
+ "data-ref": "fun:random",
+ "data-id": category.id,
+ },
+ )
+ end
+
it "does not fight with the autolinker" do
expect(PrettyText.cook(" http://somewhere.com/#known")).not_to include("hashtag")
expect(PrettyText.cook(" http://somewhere.com/?#known")).not_to include("hashtag")
diff --git a/spec/services/category_hashtag_data_source_spec.rb b/spec/services/category_hashtag_data_source_spec.rb
index e105c08003b..e5ba8bc6d3a 100644
--- a/spec/services/category_hashtag_data_source_spec.rb
+++ b/spec/services/category_hashtag_data_source_spec.rb
@@ -73,6 +73,15 @@ RSpec.describe CategoryHashtagDataSource do
expect(result.text).to eq("Silly Land > Random")
end
+ it "uses only the category name when category hashtag cards are enabled" do
+ SiteSetting.enable_category_hashtag_cards = true
+
+ result = described_class.lookup(guardian, ["fun:random"]).first
+
+ expect(result.text).to eq("Random")
+ expect(result.ref).to eq("fun:random")
+ end
+
context "with sub-sub-categories" do
before { SiteSetting.max_category_nesting = 3 }