From 71af316730ba89de58d63d5c93603b5e55491df7 Mon Sep 17 00:00:00 2001 From: Cat_yyy Date: Fri, 29 Nov 2024 01:04:54 +0900 Subject: [PATCH] feat: Added for Isct news. (#17744) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 新增category * fix: follow camelCase fix: /isct/news/en --- lib/routes/isct/namespace.ts | 6 +++++- lib/routes/isct/news.ts | 27 +++++++++++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/lib/routes/isct/namespace.ts b/lib/routes/isct/namespace.ts index 8a765050b3f1ae..2dbb6fcf8387ae 100644 --- a/lib/routes/isct/namespace.ts +++ b/lib/routes/isct/namespace.ts @@ -4,7 +4,11 @@ export const namespace: Namespace = { name: 'Institute of Science Tokyo', url: 'isct.ac.jp', lang: 'ja', - + description: ` +:::tip + 支持通过category参数筛选新闻类别。详情请查看[指南](https://docs.rsshub.app/zh/guide/parameters#%E5%86%85%E5%AE%B9%E8%BF%87%E6%BB%A4)。 + You can filter news by category through the category parameter. For more information, please refer to the [guide](https://docs.rsshub.app/guide/parameters#filtering). +:::`, ja: { name: '東京科学大学', }, diff --git a/lib/routes/isct/news.ts b/lib/routes/isct/news.ts index aedb93f10dc040..9d0e8677357d3a 100644 --- a/lib/routes/isct/news.ts +++ b/lib/routes/isct/news.ts @@ -3,12 +3,18 @@ import ofetch from '@/utils/ofetch'; import { parseDate } from '@/utils/parse-date'; import { decode } from 'entities'; -interface NewsItem { +interface MediaItem { ID: string; TITLE: string; PUBLISH_DATE: string; META_DESCRIPTION: string; MEDIA_CD: string; + MEDIA_TYPES: string; +} + +interface TagItem { + TAG_ID: string; + TAG_NAME: string; } export const route: Route = { @@ -34,11 +40,20 @@ export const route: Route = { maintainers: ['catyyy'], handler: async (ctx) => { const { lang = 'ja' } = ctx.req.param(); - const response = await ofetch(`https://www.isct.ac.jp/expansion/get_media_list_json.php?lang_cd=${lang}`); + const mediaResponse = await ofetch(`https://www.isct.ac.jp/expansion/get_media_list_json.php?lang_cd=${lang}`); + const tagResponse = await ofetch(`https://www.isct.ac.jp/expansion/get_tag_list_json.php?lang_cd=${lang}`); + + const mediaData = JSON.parse(decode(mediaResponse)); + const tagData = JSON.parse(decode(tagResponse)); + + const itemsArray: MediaItem[] = Object.values(mediaData); + const tagArray: TagItem[] = Object.values(tagData); + + const tagIdNameMapping: { [key: string]: string } = {}; - const decodedResponse = decode(response); - const data = JSON.parse(decodedResponse); - const itemsArray: NewsItem[] = Object.values(data); + for (const item of Object.values(tagArray)) { + tagIdNameMapping[item.TAG_ID] = item.TAG_NAME; + } const items = itemsArray.map((item) => ({ // 文章标题 @@ -52,7 +67,7 @@ export const route: Route = { // 如果有的话,文章作者 // author: item.user.login, // 如果有的话,文章分类 - // category: item.labels.map((label) => label.name), + category: item.MEDIA_TYPES ? [tagIdNameMapping[Number.parseInt(item.MEDIA_TYPES.replaceAll('"', ''), 10)]] : [], })); return { // 源标题