アイコンをグローバルに変更

これは、Discourse アイコンをグローバルに変更する簡単な方法です。

  1. 変更したいアイコンを右クリックし、「要素を検証」または「検証」を選択します(ブラウザによって異なります)

  2. アイコン名を見つけます

  3. Find Icons with the Perfect Look & Feel | Font Awesome で新しいアイコンを検索します。例えば、external-link-alt

  4. 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");
});
  1. Discourse でデフォルトで使用されていないアイコンは、サイト設定の svg icon subset に追加し、ブラウザを強制的にリフレッシュして変更が適用されたことを確認する必要があります。
    結果:
    image
    すべての “link” アイコンが “external-link-tab” に置き換えられます。
    アイコンがバッジなどの他のページで複数の要素に使用されている場合、そこでもアイコンが置き換えられます。

例外

注:すでに Like アイコンを変更する ことができるテーマコンポーネントがあります。このケースを例として使用します

Like を示すために使用される “heart” アイコンは、他の名前('d-liked''d-unliked')でハードコードされており、他のアイコンとは異なる方法で処理する必要があります。したがって、:heart: アイコンを :+1: アイコンに変更するには:

api.replaceIcon("d-liked", "thumbs-up");
api.replaceIcon("d-unliked", "thumbs-o-up");

like
firefox_2018-04-24_18-37-02
しかし、バッジページではアイコンは依然として “heart” です:


したがって、そのページで変更するには以下を追加します:

api.replaceIcon("heart", "thumbs-up");

別の例:

api.replaceIcon("d-watching", "eye");

これは watching アイコンを変更します:

ここでは、追跡ステータス、展開/折りたたみ、通知、もちろんいいねをカバーする他の例外を参照してください。
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 カテゴリで共有することを自由にどうぞ。


このドキュメントはバージョン管理されています - github で変更を提案してください。

「いいね!」 38