ドキュメントカテゴリの各サブカテゴリのランディングページをデフォルトでインデックスファイルにリダイレクトする

ドキュメントカテゴリをデフォルトでインデックストピックで開く組み込みオプションがあれば、さらに良いと思います。それまで、以下のJavaScriptによる回避策を使用しています:

import { apiInitializer } from "discourse/lib/api";

export default apiInitializer((api) => {

    // ドキュメントカテゴリ:カテゴリ一覧をインデックストピックにリダイレクト

    api.onPageChange(() => {
        
        const currentPath = window.location.pathname;
        const queryParams = window.location.search;
        
        const redirects = {
            
            "/c/category-1-slug/category-1-id": "/t/topic-1-slug/index-topic-1-id",
            "/c/category-2-slug/category-2-id": "/t/topic-2-slug/index-topic-2-id"
        };
        
        if (queryParams.includes("list=true")) return;
        
        const match = Object.keys(redirects).find(cat => currentPath.startsWith(cat));
        
        if (match) {
          const targetTopic = redirects[match];
          
          if (currentPath !== targetTopic) {

            const router = api.container.lookup("router:main");
            router.transitionTo(targetTopic);
          }
        }
    });

});

通常の一覧表示でドキュメントカテゴリを開くには、URLにパラメータを追加します:

/c/category-1-slug/category-1-id?list=true
「いいね!」 4