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

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

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

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

  3. ここで新しいアイコンを検索します Find Icons with the Perfect Look & Feel | Font Awesome

  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」に置き換えられます。
    アイコンがバッジなどの他のページで複数の要素に使用されている場合、そのアイコンもそこで置き換えられます。

例外

「いいね」アイコンを変更できるテーマコンポーネントがすでに存在することに注意してください (Change the Like icon)。ここではこのケースを例として使用します

「いいね」を付けるために使用される「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)


他のテーマコンポーネントを作成して、Theme component カテゴリで共有してください!


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

「いいね!」 38

Your post does help in changing icons globally but how to change the share icon in posts only? I do not want to change the link icon in the editor but, only in the posts. I checked the other posts in the forum but none of those work in the current build of Discourse, thus I am asking it here.

「いいね!」 1

thanks for the clear guide. a small point:

is it possible to change d-watching to fas fa-eye and d-tracking to far fa-eye together?

if yes, how would one add the fas icon to the svg; as I tried adding fa-eye and this header:

<script type="text/discourse-plugin" version="0.8">
api.replaceIcon('d-watching', 'fa-eye');
api.replaceIcon('d-tracking', 'eye');
</script>

but the watching icon is not working.


also I was checking other icons such as bells, and I see even when I add bells to the svg icon subset it’s not loaded:

image

image

is there anything else I should do in order to be able to use bells?

Bells is a Pro icon, so it can’t be included, our default FA5 implementation only covers the free icons.

The solid eye icon is a bit of a special case: the FontAwesome 4 eye icon was moved to the regular bundle, so in Discourse we have a matcher for it that converts ‘eye’ to ‘far-eye’. Unfortunately, this stops you from using the solid ‘eye’ icon in Discourse, because Discourse will redirect eye to far-eye. If you absolutely must use that icon, you can copy the svg into a custom icon that you can rename to something of your liking, and add that to a theme or plugin.

「いいね!」 3

thanks for the complete information :+1: , meanwhile I’ve tried several other icons, e.g. user-shield.

here is the header:
<script type="text/discourse-plugin" version="0.8">
api.replaceIcon('d-watching', 'fa-user-shield');
</script>

and I added fa-user-shield to the svg icon subset, but it still shows empty icon.

Try without the “fa-” prefix for user-shield (both in the JS code and the site setting).

still empty (tried with flag for easier snapshot):

image

That works locally for me. Did you refresh the page after making these changes?

yes, refreshed with F5 and ctrl+R just to be sure!

is there anyway to look for possible errors?

If you are familiar with the rails console, I would try logging in to the console and running SvgSprite.expire_cache and then refreshing the page to see if that does it.

「いいね!」 2

How to change the solid (fas fa-bookmark) to regular version (far fa-bookmark)?

https://fontawesome.com/icons/bookmark?style=regular

@dax Is there a way to change the default heart icon to an emoji icon?

「いいね!」 1

Currently, no, you can only replace svg icons with other svg icons, not emojis.

「いいね!」 4

FA アイコンだけでなく、追加するカスタム SVG アイコンに変更することは可能でしょうか?

はい、詳細については Introducing Font Awesome 5 and SVG icons をご覧ください。

「いいね!」 2

ありがとうございます!また、テーマで Discourse のデフォルトの SVG アイコンをカスタムアイコンに置き換えるという記事も見つけました。

最終的には、その記事で言及されているようにアップロードして名前を付ける方法が私の環境では機能しなかったため(もちろん操作ミスかもしれませんが)、SVG スプライトを直接ヘッダーファイルに埋め込むことにしました。

私のヘッダーは以下の通りです:

<svg width="0" height="0" class="hidden" style="display: none;">
    <symbol id="myicon-search" ..... </symbol>  
    <!-- ここにすべてのスプライトを記述 -->
</svg>
<script type="text/discourse-plugin" version="0.8">
    api.replaceIcon('search', 'myicon-search'); 
</script>

これは管理が簡単です。

形式が正しいか確認するために、https://svgsprit.es の SVG スプライトジェネレーターを使用しています。

「いいね!」 3

この方法で Microsoft の Fabric Icons を使用できますか?

はい、できるはずです。それらのアイコンの公式の SVG スプライト配布版は見当たりませんが、Where can I find the svg files of the icons? · Issue #1008 · OfficeDev/office-ui-fabric-core · GitHub によると、名前から個別に SVG を抽出することは可能です。

「いいね!」 4

私も同じことを試みています。投稿内の「共有」アイコンは正常に変更できましたが、エディタ内の「リンク」アイコンも変更されてしまうようです。投稿のアイコンのみを変更する方法をご存知でしょうか?

「いいね!」 3

FontAwesomeのアイコンを、テーマのアップロードセクションでアップロードしたSVGアイコンにグローバルに変更する方法はありますか?私はサイトを作成しており、discourse-solvedプラグインを使用して、トピックが解決された際のFontAwesomeアイコンを、当サイトのロゴに変更したいと考えています。プラグインの実際のコードを直接触って対応するのは難しく、このヘッダー方式でそのような対応が可能かどうかわかりません。