아이콘을 전역으로 변경

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"으로 대체됩니다.
    배지(badge)와 같은 다른 페이지의 여러 요소에서 아이콘이 사용되는 경우, 해당 위치에서도 아이콘이 대체됩니다.

예외

이미 “좋아요(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개의 좋아요

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:

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):

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)?

@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개의 좋아요

Is it possible to change to custom SVG icons we add, rather than just FA icons?

Yes, see Introducing Font Awesome 5 and SVG icons for details.

2개의 좋아요

Thank you! I also found Replace Discourse’s default SVG icons with custom icons in a theme

I ended up embedding the SVG sprite directly into the Header file, as uploading it and naming it as that article says to do did not work for me (could be operator error, of course).

So my Header is:

<svg width="0" height="0" class="hidden" style="display: none;">
    <symbol id="myicon-search" ..... </symbol>  
    <!-- all of my symbols here... -->
</svg>
<script type="text/discourse-plugin" version="0.8">
    api.replaceIcon('search', 'myicon-search'); 
</script>

And that is easy to manage.

I use the SVG sprite generator at https://svgsprit.es to make sure the format is correct.

3개의 좋아요

이 방법으로 Microsoft의 Fabric Icons를 사용할 수 있나요?

네, 가능합니다. 해당 아이콘의 공식 SVG 스프라이트 배포판은 확인되지 않지만, https://github.com/OfficeDev/office-ui-fabric-core/issues/1008에 따르면 이름을 사용하여 SVG를 하나씩 직접 추출할 수 있다고 합니다.

4개의 좋아요

저도 같은 일을 하려고 하고 있습니다. 게시글의 ‘공유’ 아이콘은 성공적으로 변경했지만, 에디터의 ‘링크’ 아이콘도 함께 변경되는 것 같습니다. 게시글의 아이콘 만 변경하는 방법에 대한 아이디어가 있을까요?

3개의 좋아요

테마 업로드 섹션에 업로드한 SVG 아이콘으로 Font Awesome 아이콘을 전역적으로 변경할 수 있는 방법이 있나요? 사이트를 작업 중인데, 특히 discourse-solved 플러그인을 통해 주제가 해결되었을 때 표시되는 Font Awesome 아이콘을 사이트 로고로 변경하고 싶습니다. 플러그인 코드를 직접 수정하는 방식으로 접근하기가 쉽지 않아서, 이 헤더 메서드가 그런 용도로 사용 가능한지 궁금합니다.