モバイルでカテゴリと「最新」を表示するにはどうすればよいですか?
このように?
「カテゴリと最新トピック」ビューを強制するために、カスタム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タブにコードを貼り付けて試すことができます。
うまくいけば教えてください。
どうもありがとうございます。試しましたが、何も変わりませんでした。![]()
以下を確認してください。
desktop_category_page_styleサイト設定がcategories_and_latest_topicsになっていること何も起こらない理由を突き止めましょう。