这是一种全局更改 Discourse 图标的方法。
-
右键点击你想要更改的图标,然后选择“检查元素”或“检查”(取决于浏览器)
-
找到图标名称
-
在 Find Icons with the Perfect Look & Feel | Font Awesome 搜索一个新图标,例如 external-link-alt
-
在
admin > customize > themes > edit code -> JS选项卡中自定义并添加代码
// {theme}/javascripts/discourse/api-initializers/init-theme.gjs
import { apiInitializer } from "discourse/lib/api";
export default apiInitializer((api) => {
api.replaceIcon("link", "external-link-tab");
});
- 默认未由 Discourse 使用的图标必须添加到站点设置
svg icon subset中,然后强制刷新浏览器以查看应用后的更改。
结果:

所有 “link” 图标都将被替换为 “external-link-tab”。
如果一个图标在其他页面的多个元素中使用,例如徽章,该图标也会在那里被替换。
例外情况
请注意,已经有一个主题组件允许你 更改 Like 图标。我使用此情况作为示例
用于点赞的 “heart” 图标与其他名称('d-liked' 和 'd-unliked')硬编码在一起,应与其他图标区别对待,因此要将
图标更改为
图标:
api.replaceIcon("d-liked", "thumbs-up");
api.replaceIcon("d-unliked", "thumbs-o-up");
![]()
![]()
但在徽章页面上,图标仍然是 “heart”:
因此,要更改该页面上的图标,我们添加:
api.replaceIcon("heart", "thumbs-up");
另一个示例:
api.replaceIcon("d-watching", "eye");
更改了关注图标:
在此处查看涵盖跟踪状态、展开/折叠、通知以及点赞的其他例外情况。
const REPLACEMENTS = {
"d-tracking": "bell",
"d-muted": "discourse-bell-slash",
"d-regular": "far-bell",
"d-watching": "discourse-bell-exclamation",
"d-watching-first": "discourse-bell-one",
"d-drop-expanded": "caret-down",
"d-drop-collapsed": "caret-right",
"d-unliked": "far-heart",
"d-liked": "heart",
"d-post-share": "link",
"d-topic-share": "link",
"notification.mentioned": "at",
"notification.group_mentioned": "users",
"notification.quoted": "quote-right",
"notification.replied": "reply",
"notification.posted": "reply",
"notification.edited": "pencil-alt",
"notification.bookmark_reminder": "discourse-bookmark-clock",
"notification.liked": "heart",
"notification.liked_2": "heart",
"notification.liked_many": "heart",
"notification.liked_consolidated": "heart",
"notification.private_message": "far-envelope",
"notification.invited_to_private_message": "far-envelope",
"notification.invited_to_topic": "hand-point-right",
"notification.invitee_accepted": "user",
"notification.moved_post": "sign-out-alt",
"notification.linked": "link",
"notification.granted_badge": "certificate",
"notification.topic_reminder": "far-clock",
"notification.watching_first_post": "discourse-bell-one",
"notification.group_message_summary": "users",
"notification.post_approved": "check",
"notification.membership_request_accepted": "user-plus",
"notification.membership_request_consolidated": "users",
"notification.reaction": "bell",
"notification.votes_released": "plus",
"notification.chat_quoted": "quote-right",
};
参考:discourse/icon-library.js at main · discourse/discourse (github.com)
请随意创建其他主题组件,并在我们的 Customization > Theme component 类别中分享!
此文档受版本控制 - 建议更改 on github。








