UX: Restore category badge colours on 404 page (#24754)

This commit is contained in:
David Taylor 2023-12-06 17:49:19 +00:00 committed by GitHub
parent 42e5bbaf38
commit 48ec946702
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -25,8 +25,17 @@ module CategoryBadge
category_url = category_url =
opts[:absolute_url] ? "#{Discourse.base_url_no_prefix}#{category.url}" : 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 # category badge structure
result << "<span data-category-id='#{category.id}'" result << "<span data-category-id='#{category.id}'"
result << " style='#{style_value}'"
result << " data-parent-category-id='#{parent_category.id}'" if parent_category result << " data-parent-category-id='#{parent_category.id}'" if parent_category
result << " data-drop-close='true' class='#{class_names}' #{description}>" result << " data-drop-close='true' class='#{class_names}' #{description}>"
result << "<span class='badge-category__name'>" result << "<span class='badge-category__name'>"

View File

@ -20,4 +20,16 @@ RSpec.describe CategoryBadge do
expect(html).to include("title='&#39; &lt;b id=&quot;x&quot;&gt;'") expect(html).to include("title='&#39; &lt;b id=&quot;x&quot;&gt;'")
end 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 end