Skip to content

Commit 303264f

Browse files
authored
fix(route): mittrchina (#13706)
* fix(route): mittrchina * Fix typos in radar.js
1 parent 52cb5e0 commit 303264f

File tree

8 files changed

+159
-52
lines changed

8 files changed

+159
-52
lines changed

lib/router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1607,7 +1607,7 @@ router.get('/hbut/cs/:type', lazyloadRouteHandler('./routes/universities/hbut/cs
16071607
router.get('/acwifi', lazyloadRouteHandler('./routes/acwifi'));
16081608

16091609
// MIT科技评论
1610-
router.get('/mittrchina/:type', lazyloadRouteHandler('./routes/mittrchina'));
1610+
// router.get('/mittrchina/:type', lazyloadRouteHandler('./routes/mittrchina'));
16111611

16121612
// iYouPort
16131613
router.get('/iyouport/article', lazyloadRouteHandler('./routes/iyouport'));

lib/routes/mittrchina/index.js

Lines changed: 0 additions & 45 deletions
This file was deleted.

lib/v2/mittrchina/index.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
const got = require('@/utils/got');
2+
const { parseDate } = require('@/utils/parse-date');
3+
const { art } = require('@/utils/render');
4+
const { join } = require('path');
5+
6+
module.exports = async (ctx) => {
7+
const typeMap = {
8+
breaking: {
9+
title: '快讯',
10+
apiPath: '/flash',
11+
},
12+
hot: {
13+
title: '本周热榜',
14+
apiPath: '/information/hot',
15+
},
16+
index: {
17+
title: '首页资讯',
18+
apiPath: '/information/index',
19+
},
20+
video: {
21+
title: '视频',
22+
apiPath: '/movie/index',
23+
},
24+
};
25+
26+
const { type = 'index' } = ctx.params;
27+
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 10;
28+
29+
const link = `https://apii.mittrchina.com${typeMap[type].apiPath}`;
30+
const { data: response } =
31+
type !== 'breaking'
32+
? await got(link, {
33+
searchParams: {
34+
limit,
35+
},
36+
})
37+
: await got.post(link, {
38+
form: {
39+
page: 1,
40+
size: limit,
41+
},
42+
});
43+
44+
let articles;
45+
if (type === 'hot') {
46+
articles = response.data;
47+
} else {
48+
articles = response.data.items;
49+
}
50+
51+
const list = articles.map((article) => ({
52+
title: article.name || article.title,
53+
author: (article.authors || article.author || []).map((author) => author.username).join(', '),
54+
category: article.typeName,
55+
description:
56+
type === 'video'
57+
? art(join(__dirname, 'templates/movie.art'), {
58+
poster: article.img,
59+
video: {
60+
address: article.address,
61+
type: article.address.split('.').pop(),
62+
},
63+
})
64+
: article.summary,
65+
pubDate: article.start_time ? parseDate(article.start_time, 'X') : undefined,
66+
id: article.id,
67+
link: `https://www.mittrchina.com/news/detail/${article.id}`,
68+
}));
69+
70+
let items = list;
71+
if (type !== 'video') {
72+
items = await Promise.all(
73+
list.map((item) =>
74+
ctx.cache.tryGet(item.link, async () => {
75+
const {
76+
data: { data: details },
77+
} = await got(`https://apii.mittrchina.com/information/details?id=${item.id}`);
78+
79+
item.description = details.content;
80+
81+
if (!item.author) {
82+
item.author = details.authors.map((a) => a.username).join(', ');
83+
}
84+
if (!item.pubDate) {
85+
item.pubDate = parseDate(details.start_time, 'X');
86+
}
87+
88+
if (details.cover) {
89+
item.enclosure_url = details.cover;
90+
item.enclosure_type = `image/${details.cover.split('.').pop()}`;
91+
}
92+
93+
return item;
94+
})
95+
)
96+
);
97+
}
98+
99+
ctx.state.data = {
100+
title: `MIT 科技评论 - ${typeMap[type].title}`,
101+
link: `https://www.mittrchina.com/${type}`,
102+
item: items,
103+
};
104+
};

lib/v2/mittrchina/maintainer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
'/:type?': ['EsuRt', 'queensferryme'],
3+
};

lib/v2/mittrchina/radar.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module.exports = {
2+
'mittrchina.com': {
3+
_name: '麻省理工科技评论',
4+
'.': [
5+
{
6+
title: '首页',
7+
docs: 'https://docs.rsshub.app/routes/new-media#ma-sheng-li-gong-ke-ji-ping-lun',
8+
source: ['/', '/news'],
9+
target: '/mittrchina/index',
10+
},
11+
{
12+
title: '快讯',
13+
docs: 'https://docs.rsshub.app/routes/new-media#ma-sheng-li-gong-ke-ji-ping-lun',
14+
source: ['/', '/breaking'],
15+
target: '/mittrchina/breaking',
16+
},
17+
{
18+
title: '本周热文',
19+
docs: 'https://docs.rsshub.app/routes/new-media#ma-sheng-li-gong-ke-ji-ping-lun',
20+
source: ['/'],
21+
target: '/mittrchina/hot',
22+
},
23+
{
24+
title: '视频',
25+
docs: 'https://docs.rsshub.app/routes/new-media#ma-sheng-li-gong-ke-ji-ping-lun',
26+
source: ['/', '/video'],
27+
target: '/mittrchina/video',
28+
},
29+
],
30+
},
31+
};

lib/v2/mittrchina/router.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = (router) => {
2+
router.get('/:type?', require('./'));
3+
};

lib/v2/mittrchina/templates/movie.art

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{{ if video }}
2+
<video poster="{{ poster }}" controls>
3+
<source src="{{ video.address }}" type="{{ video.type }}">
4+
</video>
5+
{{ /if }}

website/docs/routes/new-media.mdx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,12 +1375,6 @@ The URL of [Documentary TV Shows to Watch on Prime Video](https://www.metacritic
13751375

13761376
<Route author="fifteen42 rde9 nczitzk" example="/mirror/tingfei.eth" path="/mirror/:id" paramsDesc={['user id']} />
13771377

1378-
## MIT 科技评论 {#mit-ke-ji-ping-lun}
1379-
1380-
### 首页 {#mit-ke-ji-ping-lun-shou-ye}
1381-
1382-
<Route author="EsuRt queensferryme" example="/mittrchina/hot" path="/mittrchina/:type" paramsDesc={['类型 type,可以是 index(首页资讯)或 hot(本周热榜)']}/>
1383-
13841378
## MyGoPen {#mygopen}
13851379

13861380
### 分類 {#mygopen-fen-lei}
@@ -4330,6 +4324,18 @@ column 为 third 时可选的 category:
43304324

43314325
</Route>
43324326

4327+
## 麻省理工科技评论 {#ma-sheng-li-gong-ke-ji-ping-lun}
4328+
4329+
### 首页 {#ma-sheng-li-gong-ke-ji-ping-lun-shou-ye}
4330+
4331+
<Route author="EsuRt queensferryme" example="/mittrchina/index" path="/mittrchina/:type?" paramsDesc={['类型,见下表,默认为首页资讯']} radar="1">
4332+
4333+
| 快讯 | 本周热文 | 首页资讯 | 视频 |
4334+
| -------- | ------- | ------ | ----- |
4335+
| breaking | hot | index | video |
4336+
4337+
</Route>
4338+
43334339
## 慢雾科技 {#man-wu-ke-ji}
43344340

43354341
### 动态 {#man-wu-ke-ji-dong-tai}

0 commit comments

Comments
 (0)