From d2632bd64f7576f7fdc84aabd9b8faab07a4811a Mon Sep 17 00:00:00 2001 From: ueiu <39592269+ueiu@users.noreply.github.com> Date: Sun, 16 Jun 2024 22:44:00 +0800 Subject: [PATCH] =?UTF-8?q?fix(route):=20=E3=80=8C=E5=A0=B1=E5=B0=8E?= =?UTF-8?q?=E8=80=85=E3=80=8D=E8=B7=AF=E7=94=B1=E8=BE=93=E5=87=BA=E4=B8=8D?= =?UTF-8?q?=E5=AE=8C=E6=95=B4=20(#15912)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(route): 「報導者」路由输出不完整 * fix(route): 「報導者」路由输出不完整 --- lib/routes/twreporter/category.ts | 85 +++++++++++++++++++++++-------- 1 file changed, 65 insertions(+), 20 deletions(-) diff --git a/lib/routes/twreporter/category.ts b/lib/routes/twreporter/category.ts index 8619344a2..cf5f6bc59 100644 --- a/lib/routes/twreporter/category.ts +++ b/lib/routes/twreporter/category.ts @@ -28,28 +28,73 @@ export const route: Route = { url: 'twreporter.org/', }; +// 发现其实是个开源项目 https://github.com/twreporter/go-api,所以我们能在以下两个文件找到相应的类目 ID,从 https://go-api.twreporter.org/v2/index_page 这里拿的话复杂度比较高而且少了侧栏的几个类目: +// https://github.com/twreporter/go-api/blob/master/internal/news/category_set.go +// https://github.com/twreporter/go-api/blob/master/internal/news/category.go +const CATEGORIES = { + world: { + name: '國際兩岸', + url_name: 'world', + category_id: '63206383207bf7c5f871622c', + }, + humanrights: { + name: '人權司法', + url_name: 'humanrights', + category_id: '63206383207bf7c5f8716234', + }, + politics_and_society: { + name: '政治社會', + url_name: 'politics-and-society', + category_id: '63206383207bf7c5f871623d', + }, + health: { + name: '醫療健康', + url_name: 'health', + category_id: '63206383207bf7c5f8716245', + }, + environment: { + name: '環境永續', + url_name: 'environment', + category_id: '63206383207bf7c5f871624d', + }, + econ: { + name: '經濟產業', + url_name: 'econ', + category_id: '63206383207bf7c5f8716254', + }, + culture: { + name: '文化生活', + url_name: 'culture', + category_id: '63206383207bf7c5f8716259', + }, + education: { + name: '教育校園', + url_name: 'education', + category_id: '63206383207bf7c5f8716260', + }, + podcast: { + name: 'Podcast', + url_name: 'podcast', + category_id: '63206383207bf7c5f8716266', + }, + opinion: { + name: '評論', + url_name: 'opinion', + category_id: '63206383207bf7c5f8716269', + }, + photos_section: { + name: '影像', + url_name: 'photography', + category_id: '574d028748fa171000c45d48', + }, +}; + async function handler(ctx) { const category = ctx.req.param('category'); - const url = `https://go-api.twreporter.org/v2/index_page`; + const url = `https://go-api.twreporter.org/v2/posts?category_id=${CATEGORIES[category].category_id}`; + const home = `https://www.twreporter.org/categories/${CATEGORIES[category].url_name}`; const res = await ofetch(url); - const list = res.data[category]; - - let name = list[0].category_set[0].category.name; - let categoryID = category; - switch (categoryID) { - case 'photos_section': - categoryID = 'photography'; - - break; - case 'politics_and_society': - categoryID = categoryID.replaceAll('_', '-'); - name = '政治社會'; - - break; - default: - break; - } - const home = `https://www.twreporter.org/categories/${categoryID}`; + const list = res.data.records; const out = await Promise.all( list.map((item) => { @@ -64,7 +109,7 @@ async function handler(ctx) { ); return { - title: `報導者 | ${name}`, + title: `報導者 | ${CATEGORIES[category].name}`, link: home, item: out, };