Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion javascripts/discourse/initializers/tag-icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ function iconTagRenderer(tag, params) {
// Get the rendered default tag markup.
const renderedTag = defaultRenderTag(tag, params);

// Handle both string tags (legacy) and object tags (new format: { id, name, slug })
// This maintains backwards compatibility with Discourse versions before PR #36678
const tagName = typeof tag === "string" ? tag : tag.name;

// Get the tag configuration list from the settings.
const tagIconList = settings.tag_icon_list.split("|");

// Returns the tag configuration if found.
const tagIconItem = tagIconList.find(
(line) =>
line.indexOf(",") > -1 &&
tag.toLowerCase() === line.substr(0, line.indexOf(",")).toLowerCase()
tagName.toLowerCase() === line.substr(0, line.indexOf(",")).toLowerCase()
);

// Update the tag markup with an SVG icon, and inline-styles for the colors.
Expand Down
11 changes: 11 additions & 0 deletions spec/system/tag_icons_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
fab!(:user)

let(:topic_page) { PageObjects::Pages::Topic.new }
let(:topic_list) { PageObjects::Components::TopicList.new }
let(:tag_icon) { PageObjects::Components::TagIcon.new }
let!(:theme) { upload_theme_component }

Expand All @@ -28,6 +29,16 @@
)
end

it "displays tag with icon on topics list page" do
visit "/latest"
expect(topic_list).to have_topic(topic)
expect(tag_icon).to have_icon_for_tag(
tag_name: "support",
icon: "question-circle",
color: "#ff0000",
)
end

it "displays tag without icon when not configured" do
theme.update_setting(:tag_icon_list, "")
theme.save!
Expand Down