إعادة توجيه صفحة الهبوط لكل فئة فرعية إلى ملف الفهرس بشكل افتراضي لفئات التوثيق

كما أني أرحب بوجود خيار مدمج لفتح فئة الوثائق مع موضوع فهرسي بشكل افتراضي. حتى ذلك الحين، أستخدم حل التخطي التالي بلغة 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 إعجابات