feat: Added <category> for Isct news. (#17744)

* 新增category

* fix: follow camelCase
fix: /isct/news/en
This commit is contained in:
Cat_yyy 2024-11-29 01:04:54 +09:00 committed by GitHub
parent 13696b98e4
commit 71af316730
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 7 deletions

View File

@ -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: '東京科学大学',
},

View File

@ -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 decodedResponse = decode(response);
const data = JSON.parse(decodedResponse);
const itemsArray: NewsItem[] = Object.values(data);
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 } = {};
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 {
// 源标题