是否可以更改员工通知的图标?

Is it possible to change the icon used on Staff Notices, either through css or a setting that I just haven’t found? Preferably we’d like to swap it out for a custom picture rather than a FA icon.

1 个赞

We do not have a setting for that and I think doing it in CSS only is difficult, but you can create a theme component to replace it.

In CSS, you will hide the old icon:

.post-notice {
  .d-icon-user-shield {
    display: none;
  }
}

In JavaScript (you put this in <head> of the theme component), you will decorate the notice and add the new icon:

<script type="text/discourse-plugin" version="0.8">
  const { iconNode } = require("discourse-common/lib/icon-library");
  api.decorateWidget('post-notice:before', helper => {
    return iconNode('heart');
  });
</script>

… or if you want to replace with an image…:

<script type="text/discourse-plugin" version="0.8">
  api.decorateWidget('post-notice:before', helper => {
    return helper.h('img', {
      src: 'https://www.discourse.org/a/img/home-spot-1.png',
      style: 'margin-right: 0.65em',
      height: 30,
      width: 30
    });
  });
</script>

With themes and theme components, the sky is the limit. If you want to learn more, we have a resource for that:

12 个赞

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

我已经试过了;第一个 JS 代码片段需要稍作更新。

现在需要将其放入主题组件(或主题)的 JS 选项卡中:

import { apiInitializer } from "discourse/lib/api";
import { iconNode } from "discourse-common/lib/icon-library";

export default apiInitializer("0.11.1", (api) => {
  api.decorateWidget("post-notice:before", () => {
    return iconNode("heart");
  });
});

抱歉,我没看如何使用图片。

3 个赞

添加到我的主题后,我看到了一个警告,因为 Upcoming post stream changes - How to prepare themes and plugins

我尝试这样做是因为我想知道它是否仅影响员工笔记,还是也影响新用户和回访用户笔记,因为这些都是帖子通知。
它会影响所有帖子通知,而上面的 CSS 只会隐藏盾牌。因此,您在新用户和回访用户通知上会看到两个图标。

1 个赞

那这一切都有些不尽如人意!!

我急于发布那条消息,却忘了删除 api.decorateWidget。我一定是在没注意的情况下忽略了我网站上的错误。

我相信 CSS 可以被更好地定位,但我刚刚发现了 Quote Callouts - 我认为这能更好地满足我的用例。

3 个赞