隐藏子类别而不隐藏其在主题列表中的主题?

是的,我在本地测试时漏掉了类别设置的问题。我已经修改了上面的代码片段,现在应该可以正常工作了。

上面的代码片段允许你设置要生效的类别。如果你希望它在所有类别上生效,可以使用类似下面的代码。

<script type="text/discourse-plugin" version="0.8">
  const { on } = require("discourse-common/utils/decorators");

  const useParentCategory = function () {
    const parentCategory = this.attrs.topic.category.parentCategory;

    if (parentCategory) {
     this.attrs.topic.set("category", parentCategory);
    }
  };

  api.modifyClass("component:topic-list-item", {
    @on("didReceiveAttrs")
    setCategory() {
      useParentCategory.call(this);
    }
  });

  api.modifyClass("component:latest-topic-list-item", {
    @on("didReceiveAttrs")
    setCategory() {
      useParentCategory.call(this);
    }
  });
</script>