我如何在手机上查看分类和“最新”?

如何在移动设备上查看类别和“最新”?

像这样吗?

我看了,他们使用了一些自定义 JS 代码来强制显示“类别和最新主题”视图。

我没有检查是否有更好的方法;这是他们所做的(我已将代码现代化并添加了一些注释):

import { apiInitializer } from "discourse/lib/api";
import CategoriesAndLatestTopics from "discourse/components/categories-and-latest-topics";
import CategoryList from "discourse/models/category-list";
import { MAX_UNOPTIMIZED_CATEGORIES } from "discourse/lib/constants";

export default apiInitializer((api) => {
  // 强制显示“类别和最新主题”视图。
  api.modifyClass(
    "component:discovery/categories-display",
    (Superclass) =>
      class extends Superclass {
        get categoriesComponent() {
          if (this.args.parentCategory) {
            return super.categoriesComponent;
          } else {
            return CategoriesAndLatestTopics;
          }
        }
      }
  );

  // 与原始代码相同,只是修改了“this.site.desktopView”检查,
  // 因此它也能为移动设备找到最新主题。
  api.modifyClass(
    "route:discovery-categories",
    (Superclass) =>
      class extends Superclass {
        async findCategories(parentCategory) {
          let model;

          let style = this.siteSettings.desktop_category_page_style;
          if (this.site.categories.length > MAX_UNOPTIMIZED_CATEGORIES) {
            style = "categories_only";
          }

          if (
            style === "categories_and_latest_topics" ||
            style === "categories_and_latest_topics_created_date"
          ) {
            model = await this._findCategoriesAndTopics(
              "latest",
              parentCategory
            );
          } else if (style === "categories_and_top_topics") {
            model = await this._findCategoriesAndTopics(
              "top",
              parentCategory
            );
          } else {
            PreloadStore.remove("topic_list");
            model = await CategoryList.list(this.store, parentCategory);
          }

          return model;
        }
      }
  );
});

您可以尝试将代码粘贴到新的组件 → 编辑代码 → JS 选项卡中。
如果有效,请告诉我。

2 个赞

非常感谢。我试过了,但什么都没改变。:thinking:

我将检查以下几点,请确保:

  • 代码位于 JS 选项卡中(而不是其他位置)
  • 您的代码已启用(如果您创建了 TC,请确保它已附加到主题)
  • 您的 desktop_category_page_style 站点设置为 categories_and_latest_topics
  • 浏览器控制台中是否有错误

让我们看看能否找出原因。

我认为我都是这样做的。复制正确吗?

1 个赞

您可以删除重复项。这很可能是它不起作用的原因(这 5 行):

1 个赞

现在有什么东西要来了!但当我使用“现代类别和组”事物时,却不行。

:sweat_smile: