Skip to content

Commit

Permalink
feat: Added <category> for Isct news. (DIYgod#17744)
Browse files Browse the repository at this point in the history
* 新增category

* fix: follow camelCase
fix: /isct/news/en
  • Loading branch information
catyyy authored Nov 28, 2024
1 parent 13696b9 commit 71af316
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
6 changes: 5 additions & 1 deletion lib/routes/isct/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '東京科学大学',
},
Expand Down
27 changes: 21 additions & 6 deletions lib/routes/isct/news.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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) => ({
// 文章标题
Expand All @@ -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 {
// 源标题
Expand Down

0 comments on commit 71af316

Please sign in to comment.