From 48ec946702f81a4aed95c31eb54bc5e962db047c Mon Sep 17 00:00:00 2001 From: David Taylor Date: Wed, 6 Dec 2023 17:49:19 +0000 Subject: [PATCH] UX: Restore category badge colours on 404 page (#24754) --- lib/category_badge.rb | 9 +++++++++ spec/lib/category_badge_spec.rb | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/category_badge.rb b/lib/category_badge.rb index b559a8a98a2..aca60eedfd9 100644 --- a/lib/category_badge.rb +++ b/lib/category_badge.rb @@ -25,8 +25,17 @@ module CategoryBadge category_url = opts[:absolute_url] ? "#{Discourse.base_url_no_prefix}#{category.url}" : category.url + # styles + styles = { + "--category-badge-color": "##{category.color}", + "--category-badge-text-color": "##{category.text_color}", + } + styles["--parent-category-badge-color"] = "##{parent_category.color}" if parent_category + style_value = styles.map { |k, v| "#{k}: #{ERB::Util.html_escape(v)};" }.join(" ") + # category badge structure result << "" result << "" diff --git a/spec/lib/category_badge_spec.rb b/spec/lib/category_badge_spec.rb index 3eada370f23..401833b7c65 100644 --- a/spec/lib/category_badge_spec.rb +++ b/spec/lib/category_badge_spec.rb @@ -20,4 +20,16 @@ RSpec.describe CategoryBadge do expect(html).to include("title='' <b id="x">'") end + + it "includes color vars" do + c = Fabricate(:category, color: "123456", text_color: "654321") + html = CategoryBadge.html_for(c) + + expect(html).to have_tag( + "span[data-category-id]", + with: { + style: "--category-badge-color: #123456; --category-badge-text-color: #654321;", + }, + ) + end end