diff --git a/docusaurus.config.ts b/docusaurus.config.ts index 0abfa95284923fc939fac065b8391da5a09129dc..7974dcfab3ccadae8cb6ac1b4b065e4d02581770 100644 --- a/docusaurus.config.ts +++ b/docusaurus.config.ts @@ -187,7 +187,7 @@ const config: Config = { }, { label: '文档', - to: `${CDN_PREFIX}`, + to: `/docs/`, className: 'gai-navbar-item', activeBaseRegex: '^/docs.*', }, @@ -305,7 +305,7 @@ const config: Config = { { id: 'openapi/v1', label: '接口文档', - route: `${CDN_PREFIX}/openapi/v1`, + route: `/docs/openapi/v1`, showNavLink: false, configuration: { url: `${SITE_URL}/v1/yaml`, diff --git a/src/components/ServerlessAPIServices.jsx b/src/components/ServerlessAPIServices.jsx index 8975a560314cc7a899cb93807face2e65c41de38..60fd31c40505792cb05d464514fc6f9095d8c7b0 100644 --- a/src/components/ServerlessAPIServices.jsx +++ b/src/components/ServerlessAPIServices.jsx @@ -7,11 +7,7 @@ const API_CONFIG = { SERVERLESS_SERVICE_CATEGORY: 'serverless-service', }; -/** URL 参数键名 */ -const URL_PARAMS = { - VENDOR: 'vendor', - TAG: 'tag', -}; + /** 筛选器默认值 */ const FILTER_DEFAULTS = { @@ -420,56 +416,26 @@ function ServicesTable({ services, showOperations, hostUrl }) { // ============================================================================ /** - * URL 参数管理 Hook + * 筛选参数管理 Hook */ -function useURLParams( +function useFilterParams( defaultVendor = FILTER_DEFAULTS.ALL, defaultTag = FILTER_DEFAULTS.ALL, ) { const [selectedVendor, setSelectedVendor] = useState(defaultVendor); const [selectedTag, setSelectedTag] = useState(defaultTag); - // 初始化:从 URL 读取参数,如果没有则使用默认值 + // 初始化:使用默认值 useEffect(() => { - const urlParams = new URLSearchParams(window.location.search); - const vendorParam = urlParams.get(URL_PARAMS.VENDOR); - const tagParam = urlParams.get(URL_PARAMS.TAG); - - if (vendorParam) { - setSelectedVendor(vendorParam); - } else if (defaultVendor !== FILTER_DEFAULTS.ALL) { + if (defaultVendor !== FILTER_DEFAULTS.ALL) { setSelectedVendor(defaultVendor); } - if (tagParam) { - setSelectedTag(tagParam); - } else if (defaultTag !== FILTER_DEFAULTS.ALL) { + if (defaultTag !== FILTER_DEFAULTS.ALL) { setSelectedTag(defaultTag); } }, [defaultVendor, defaultTag]); - // 同步:更新 URL 参数 - useEffect(() => { - const urlParams = new URLSearchParams(window.location.search); - - // 处理厂商参数 - if (selectedVendor === FILTER_DEFAULTS.ALL) { - urlParams.delete(URL_PARAMS.VENDOR); - } else { - urlParams.set(URL_PARAMS.VENDOR, selectedVendor); - } - - // 处理分类参数 - if (selectedTag === FILTER_DEFAULTS.ALL) { - urlParams.delete(URL_PARAMS.TAG); - } else { - urlParams.set(URL_PARAMS.TAG, selectedTag); - } - - const newUrl = `${window.location.pathname}${urlParams.toString() ? '?' + urlParams.toString() : ''}`; - window.history.pushState({}, '', newUrl); - }, [selectedVendor, selectedTag]); - return { selectedVendor, selectedTag, @@ -671,7 +637,7 @@ export default function ServerlessAPIServices({ // 状态管理 const { selectedVendor, selectedTag, setSelectedVendor, setSelectedTag } = - useURLParams(defaultVendor, defaultTag); + useFilterParams(defaultVendor, defaultTag); const { loading, services, vendors, tags, showOperations, error } = useServicesData(hostUrl); const { filteredServices, filteredOpsCount } = useFilteredServices(