Category icons component

theme-component
(Penar Musaraj) #1

Repo link:

https://github.com/pmusaraj/discourse-category-icons

Installation instructions: How do I install a Theme or Theme Component?

What this does?

This component allows category badge links to have icons next to the category name. Here is an example of how this would look, with category style set to none:

Here is how this would look with category style set to box:

Configuration is pretty straightforward:

Note that this component also lets you override the category lock icon used to denote private categories.

Issues

  • Does not correctly respect the icon color when using with the bullet category style. In general, though, this shouldn’t be used with the bullet or bar category styles, the UI would be unnecessarily busy.

See also the Tag Icons component, which does the same thing for tags.

34 Likes
Tag icons component
Add a custom fontawesome icon and color to your tag
(Emre) #3

This component has had an impact on our forum in an artistic way. I like it.

However there is a problem with category names. I created a category with the name of “Doğa Bilimleri”, but later changed its name to “Bilim” and created a sub-category with the name of “Doğa Bilimleri”.

Before:
Before

After:
After

I only assigned an icon for the category of “Doğa Bilimleri”, not for “Bilim”.

doga-bilimleri-flask

But the flask icon has been assigned for both “Bilim” and its sub-category “Doğa Bilimleri”.

Flask-assigned-for-both

I cannot also assign an icon to a category whose name I change if I use the new name of it, yet the old name always works. (I solved this one: This is all about “category slug”. If you leave the category slug with the old name, you will experience same pseudo-problem.)

Edit: I figured out why the flask icon is assigned for the main category. It is because both the main category and the sub-category include same word “Bilim”. Even if I give a random name like “abcdefbilimghjk” in the category icon list, it will still assign the icon I choose to the category “Bilim”, since the random name includes the word “bilim”.

abcdefbilimghjk

2 Likes
(Penar Musaraj) #4

Hi Emre, thanks for the report, I’ve now fixed the issue with loose matching of slugs. If you update the theme, it should be resolved, “abcdefbilimghjk” will no longer apply the icon to the “bilim” slug.

6 Likes
(Emre) #5

It’s been perfectly resolved. Thanks for the update :+1:

4 Likes
(📹Scammer Revolts💻) #6

This is an awesome component! Works great on my site! ty for doing this :smiley:!awe

5 Likes
#7

Can I use this icon as “js”?

image

Only bash has the icon, the others has an emty space.

image

What do I miss?

(Régis Hanol) #8

Have a look here to learn how to use new font awesome icons

2 Likes
#9

Thanks, but how that breaks down to using this component as a plugin user?

Should I wait for something to merge to master before I can use the plugin?

Or did I misunderstand the method to define how can I specify my font awesome icons?

(Penar Musaraj) #10

Use fab-js instead of js in both fields since it’s a brand icon and FA groups brand icons separately.

Same for the Java icon, though you should be on tests-passed for that to work, because the Java icon was added to FontAwesome recently.

3 Likes
(Piyush Singh) #11

Can this component be extended to support custom made svg icons?

(Penar Musaraj) #12

Custom SVG icons are already supported in plugins, see Introducing Font Awesome 5 and SVG icons for details. Custom SVG icon support in themes is in the works.

5 Likes
(Piyush Singh) #13

Thank you for quick response. I will look into it.

(Luka Renko) #14

First, a big thank you to @pmusaraj for making this great theme-component.

I have configured it on my site, but have two issues:

There seems to be no way I can “attach” any icon to Jadran category
I have tried with various icons, even the ones that are working on other categories with no success.

Configuration is the same as for other categories:

It seems that pull-downs in category view, does not respect the icon color (white).
Here it looks the worst - gray on gray.

Elsewhere, white color is respected:

(Luka Renko) #15

I have an idea, why “Jadran” does not work: I have another category “Jadranje”, which includes first name. I would expect that slug would be checked with exact match (everything between /), right?

(Penar Musaraj) #16

In the URL you posted https://pojalabanda.com/c/potovanja/jadran, I see the icon next to Jadran.

I do see the style issue, it’s something that’s been recently introduced, I’ll look for a solution.

3 Likes
(Luka Renko) #17

Yes, I got idea for workaround: have replaced the order of “rules” in the config, so that longer name is after shorter:
image

It works now!

Thanks for checking the problem and for confirming style issue.

2 Likes
(Luka Renko) #18

Is there a possibility to upload own svg icon and then use it as category icon? I tried to upload it on Category icons upload, but not sure how should I reference it?

Or am I completely on wrong track here?

(Penar Musaraj) #19

It’s slightly different, you need to upload an svg sprite. See this:

3 Likes
(Penar Musaraj) #20

I have pushed a fix for the style issue in core: UX: Inherit badge icon color · discourse/discourse@8d098df · GitHub

Once this passes tests, you need to rebuild your app, icon colors should then respect the badge color.

4 Likes
(David Kingham) #21

Do you have any plans to extend this to the sub-category boxes Penar? Would be awesome to have them everywhere. My site looks great with all these icons now, appreciate this!

3 Likes