获取主题标题以显示在自定义英雄横幅中

我一直在使用 router 和 discovery 来根据显示的页面创建动态 hero,但是当我进入单个主题页面时,我找不到将主题标题传递到模板的方法。

有没有办法在这里检索主题标题?

import { inject as service } from "@ember/service";
import Component from "@glimmer/component";
import { defaultHomepage } from "discourse/lib/utilities";

export default class BcnHero extends Component {
  @service router;
  @service discovery;

  get showHero() {
    const { currentRouteName } = this.router;
    const { category } = this.discovery;

    let categoryName = "";
    let categoryDescription = "";
    if (category) {
      categoryName = category.name;
      categoryDescription = category.description;
    }

    if (currentRouteName === `discovery.${defaultHomepage()}`) {
      return { homepageHero: true };
    }

    if (currentRouteName === "discovery.category" || currentRouteName.startsWith("topic")) {
      return { dynamicHero: true, title: categoryName, subtitle: categoryDescription };
    }
    return { emptyHero: true };
  }
}
1 个赞