-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FEATURE: display category icon in post body #36
Conversation
This commit allows displaying category icons in the body of the post. Related meta topic: https://meta.discourse.org/t/category-icons-dont-show-up-in-post-text/315851
if (!color || color?.match(/categoryColo(u*)r/g)) { | ||
opts.color = `#${cat.color}`; | ||
} | ||
slugMap[cat.slug.toLowerCase()] = opts; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if there are multiple categories with empty slugs?
(I'm basing this hypothetical off https://github.com/discourse/discourse/blob/main/app/models/category.rb#L688)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a
if (slug && icon) {
Therefore, the category with an empty slug will not enter this statement. 😊
} | ||
} | ||
api.decorateCookedElement((elem) => { | ||
const categorgHashtags = elem.querySelectorAll( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit) categorgHashtags
seems like a typo - maybe categoryHashtags
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
if (match === "partial") { | ||
if (!cat.slug.toLowerCase().includes(slug.toLowerCase())) { | ||
continue; | ||
} | ||
} else { | ||
if (cat.slug.toLowerCase() !== slug.toLowerCase()) { | ||
continue; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(minor) perhaps this could be simplified to something a single guard clause?
if (match === "partial") { | |
if (!cat.slug.toLowerCase().includes(slug.toLowerCase())) { | |
continue; | |
} | |
} else { | |
if (cat.slug.toLowerCase() !== slug.toLowerCase()) { | |
continue; | |
} | |
} | |
if ((match === "partial" && !cat.slug.toLowerCase().includes(slug.toLowerCase())) || cat.slug.toLowerCase() !== slug.toLowerCase()) { | |
continue | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably could DRY out the repeated lowerCase calls too 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
@tyb-talks Can you review it again for me? I rewrote it using the new API of Discourse instead of calling |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sweet, this is a simpler solution. lg2m! 🚢
This commit allows displaying category icons in the body of the post.
Screenshots
New setting:
Before change:
After change:
Related meta topic: https://meta.discourse.org/t/category-icons-dont-show-up-in-post-text/315851