Redirect the landing page for each subcategory to index file by default for documentation categories

I would also welcome a built-in option to have a Doc Category opened with an index topic by default. Until then, I’m using the following JavaScript workaround:

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

export default apiInitializer((api) => {

    // Doc Categories: redirect category listing to index topic

    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);
          }
        }
    });

});

To open the Doc Category with the regular listing, add a parameter to the URL:

/c/category-1-slug/category-1-id?list=true
4 לייקים