fix(route): 「報導者」路由输出不完整 (#15912)

* fix(route): 「報導者」路由输出不完整

* fix(route): 「報導者」路由输出不完整
This commit is contained in:
ueiu 2024-06-16 22:44:00 +08:00 committed by GitHub
parent dc0f222658
commit d2632bd64f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 65 additions and 20 deletions

View File

@ -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,
};