From 8c7c1b5cbe764bdc8e6e8a7b06764b87e3e05681 Mon Sep 17 00:00:00 2001 From: chiba Date: Thu, 19 Nov 2026 14:31:18 +0800 Subject: [PATCH 1/3] fix(cloudflare): 301 docs URLs removed by #383 and #1001 to their new pages Add 17 entries to GONE_PAGES so the old Overview / Refresh Token / Error Codes pages (merged into /docs/api by #383), the market endpoints moved by #1001, and the /docs/content/news category redirect instead of 404. resolveGone() carries the locale prefix and .md twin, covering 51 page URLs plus their markdown twins. Co-Authored-By: Claude Opus 5.5 --- functions/[[path]].ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/functions/[[path]].ts b/functions/[[path]].ts index 3761c95e..c9cf9f67 100644 --- a/functions/[[path]].ts +++ b/functions/[[path]].ts @@ -181,6 +181,27 @@ const GONE_PAGES: Record = { '/docs/api/us_etf_dividend_info': '/docs/api/dividends', '/docs/api/us_company_dividends': '/docs/api/dividends', '/docs/api/us_etf_files': '/docs/api/company_profile', + // 文档重组后的旧地址:#383 把接入说明、刷新 Token、错误码并进 API Reference + // (openapi.yaml 的 x-pages);#1001 把市场类接口拆到 market 类目下。 + // error-codes 的错误码视图靠 ?page=error-codes 切换,这里先落到 /docs/api。 + '/docs/how-to-access-api': '/docs/api', + '/docs/refresh-token-api': '/docs/api', + '/docs/error-codes': '/docs/api', + '/docs/quote/pull/trade-session': '/docs/market/trade-session', + '/docs/quote/pull/trade-day': '/docs/market/trade-days', + '/docs/quote/pull/market_temperature': '/docs/market/market-temperature', + '/docs/quote/pull/history_market_temperature': '/docs/market/history-market-temperature', + '/docs/fundamental/market/market-status': '/docs/market/market-status', + '/docs/fundamental/market/unusual-items': '/docs/market/unusual-items', + '/docs/fundamental/calendar/dividend-calendar': '/docs/market/calendar/dividend-calendar', + '/docs/fundamental/calendar/earnings-calendar': '/docs/market/calendar/earnings-calendar', + '/docs/fundamental/calendar/ipo-calendar': '/docs/market/calendar/ipo-calendar', + '/docs/fundamental/calendar/macro-calendar': '/docs/market/calendar/macro-calendar', + '/docs/fundamental/calendar/meeting-calendar': '/docs/market/calendar/meeting-calendar', + '/docs/fundamental/calendar/merge-calendar': '/docs/market/calendar/merge-calendar', + '/docs/fundamental/calendar/split-calendar': '/docs/market/calendar/split-calendar', + // 资讯分类目录没有落地页,sitemap 里只有它下面的 news 页 + '/docs/content/news': '/docs/content/news/news', } /** From daecb66929350966e980c6fe9459d81759487acf Mon Sep 17 00:00:00 2001 From: chiba Date: Thu, 19 Nov 2026 14:36:29 +0800 Subject: [PATCH 2/3] fix(cloudflare): redirect /docs/error-codes to the error-codes view Per review, /docs/error-codes now 301s to /docs/api?page=error-codes, the address used by in-site error code links. resolveGone() accepts a target with its own query: page requests get the target query first and the incoming query appended; .md requests drop the target query and go to the markdown twin (/docs/api.md, which already contains the error code table), so they never become ?page=error-codes.md. Co-Authored-By: Claude Opus 5.5 --- functions/[[path]].ts | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/functions/[[path]].ts b/functions/[[path]].ts index c9cf9f67..4df7f4ce 100644 --- a/functions/[[path]].ts +++ b/functions/[[path]].ts @@ -183,10 +183,11 @@ const GONE_PAGES: Record = { '/docs/api/us_etf_files': '/docs/api/company_profile', // 文档重组后的旧地址:#383 把接入说明、刷新 Token、错误码并进 API Reference // (openapi.yaml 的 x-pages);#1001 把市场类接口拆到 market 类目下。 - // error-codes 的错误码视图靠 ?page=error-codes 切换,这里先落到 /docs/api。 + // 错误码在 API Reference 里靠 ?page=error-codes 切换视图(站内链接都用这个地址), + // 目标里的 query 怎么处理见 resolveGone()。 '/docs/how-to-access-api': '/docs/api', '/docs/refresh-token-api': '/docs/api', - '/docs/error-codes': '/docs/api', + '/docs/error-codes': '/docs/api?page=error-codes', '/docs/quote/pull/trade-session': '/docs/market/trade-session', '/docs/quote/pull/trade-day': '/docs/market/trade-days', '/docs/quote/pull/market_temperature': '/docs/market/market-temperature', @@ -209,15 +210,26 @@ const GONE_PAGES: Record = { * * en 前缀直接丢掉:en 是 root locale,规则⑥本来就会把 /en 收敛到根,带着它跳会 * 变成 301 → 302 两跳。 + * + * 目标可以自带 query(如 `/docs/api?page=error-codes`): + * - 页面请求:目标 query 在前、来源 query 接在后面, + * `/docs/error-codes?x=1` → `/docs/api?page=error-codes&x=1`; + * - `.md` 请求:`.md` 加在路径上,目标 query 丢掉。`?page=` 只是前端切换视图用的, + * markdown 孪生(如 `/docs/api.md`)本身就是整份原文、已含该视图的内容, + * 所以 `/docs/error-codes.md` → `/docs/api.md`,不会变成 `?page=error-codes.md`。 + * 来源 query 两种情况都原样保留。 */ -function resolveGone(path: string): string | null { +function resolveGone(path: string, search: string): string | null { const m = /^\/(en|zh-CN|zh-HK)(\/.*)$/.exec(path) const bare = m ? m[2] : path const isMd = bare.endsWith('.md') const target = GONE_PAGES[isMd ? bare.slice(0, -'.md'.length) : bare] if (!target) return null const prefix = m && m[1] !== 'en' ? `/${m[1]}` : '' - return `${prefix}${target}${isMd ? '.md' : ''}` + const [targetPath, targetQuery = ''] = target.split('?') + if (isMd) return `${prefix}${targetPath}.md${search}` + const query = [targetQuery, search.slice(1)].filter(Boolean).join('&') + return `${prefix}${targetPath}${query ? `?${query}` : ''}` } /** @@ -289,8 +301,8 @@ export const onRequest = async ({ request, next }: Ctx): Promise => { // ⑤ 已下线页面 → 301 到现存的同类页面。排在 /en 收敛之前,让 /en/docs/... 一步 // 到位;排在末尾斜杠之后,让 .../us_asset_overview/ 先规范化再查表。 - const gone = resolveGone(path) - if (gone) return Response.redirect(new URL(gone + url.search, url).toString(), 301) + const gone = resolveGone(path, url.search) + if (gone) return Response.redirect(new URL(gone, url).toString(), 301) // ⑥ /en 前缀收敛(_release.conf:31)。站点域名上只放行 `_llms.conf` 已接管的 // /en/docs/**.md,与 nginx 一致:/en/skill-install.md 等先 302 掉前缀。 From 2b748fec12896a9f59d01d2c1e67dfaf55f1ea3c Mon Sep 17 00:00:00 2001 From: chiba Date: Thu, 19 Nov 2026 17:49:40 +0800 Subject: [PATCH 3/3] fix(cloudflare): send how-to-access-api and refresh-token-api to the authentication view /docs/api without a query lands on Overview (resolvePage() defaults to overview). Both pages were merged into x-pages.authentication by #383, so point them at /docs/api?page=authentication, the same way error-codes goes to ?page=error-codes. The .md twins still go to /docs/api.md. Suggested in review by @twosugar. Co-Authored-By: Claude Opus 5.5 --- functions/[[path]].ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/functions/[[path]].ts b/functions/[[path]].ts index 4df7f4ce..676c704f 100644 --- a/functions/[[path]].ts +++ b/functions/[[path]].ts @@ -183,10 +183,11 @@ const GONE_PAGES: Record = { '/docs/api/us_etf_files': '/docs/api/company_profile', // 文档重组后的旧地址:#383 把接入说明、刷新 Token、错误码并进 API Reference // (openapi.yaml 的 x-pages);#1001 把市场类接口拆到 market 类目下。 - // 错误码在 API Reference 里靠 ?page=error-codes 切换视图(站内链接都用这个地址), + // API Reference 靠 ?page= 切换视图,不带 query 落在 Overview:接入说明、刷新 Token + // 并进了 authentication,错误码是 error-codes(站内链接都用这个地址)。 // 目标里的 query 怎么处理见 resolveGone()。 - '/docs/how-to-access-api': '/docs/api', - '/docs/refresh-token-api': '/docs/api', + '/docs/how-to-access-api': '/docs/api?page=authentication', + '/docs/refresh-token-api': '/docs/api?page=authentication', '/docs/error-codes': '/docs/api?page=error-codes', '/docs/quote/pull/trade-session': '/docs/market/trade-session', '/docs/quote/pull/trade-day': '/docs/market/trade-days',