Skip to content

Commit 3face66

Browse files
author
zmvw
committed
fix(route):fixed the parameter section and add an
english site.
1 parent 70c4fe9 commit 3face66

File tree

3 files changed

+74
-14
lines changed

3 files changed

+74
-14
lines changed

lib/routes/shisu/en.ts

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { Route } from '@/types';
2+
import { load } from 'cheerio';
3+
import { parseDate } from '@/utils/parse-date';
4+
import { got } from 'got';
5+
import cache from '@/utils/cache';
6+
7+
export const route: Route = {
8+
path: '/en/features',
9+
categories: ['university'],
10+
example: '/shisu/en/features',
11+
features: {
12+
requireConfig: false,
13+
requirePuppeteer: false,
14+
antiCrawler: false,
15+
supportBT: false,
16+
supportPodcast: false,
17+
supportScihub: false,
18+
},
19+
radar: [
20+
{
21+
source: ['en.shisu.edu.cn/resources/features/'],
22+
},
23+
],
24+
name: 'FEATURED STORIES',
25+
maintainers: ['Duuckjing'],
26+
description: 'Read a series of in-depth stories about SISU faculty, students, alumni and beyond campus.',
27+
handler: async () => {
28+
const url = 'https://en.shisu.edu.cn';
29+
const { body: r } = await got(`${url}/resources/features/`, { https: { rejectUnauthorized: false } });
30+
// eslint-disable-next-line no-console
31+
const $ = load(r);
32+
const itemsoup = $('.tab-con:nth-child(1) ul li')
33+
.toArray()
34+
.map((i0) => {
35+
const i = $(i0);
36+
const img = i.find('img').attr('src');
37+
const link = `${url}${i.find('h3>a').attr('href')}`;
38+
return {
39+
title: i.find('h3>a').text().trim(),
40+
link,
41+
pubDate: parseDate(i.find('p.time').text()),
42+
itunes_item_image: `${url}${img}`,
43+
};
44+
});
45+
const items = await Promise.all(
46+
itemsoup.map((j) =>
47+
cache.tryGet(j.link, async () => {
48+
const { body: r } = await got(j.link, { https: { rejectUnauthorized: false } });
49+
const $ = load(r);
50+
j.description = $('.details-con').html()!;
51+
return j;
52+
})
53+
)
54+
);
55+
return {
56+
title: 'FEATURED STORIES',
57+
link: `${url}/resources/features/`,
58+
item: items,
59+
};
60+
},
61+
};

lib/routes/shisu/namespace.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import type { Namespace } from '@/types';
22

33
export const namespace: Namespace = {
44
name: '上海外国语大学',
5-
url: 'news.shisu.edu.cn',
5+
url: 'shisu.edu.cn',
66
};

lib/routes/shisu/news.ts

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import { Route } from '@/types';
22
import cache from '@/utils/cache';
3-
import got from '@/utils/got';
3+
import ofetch from '@/utils/ofetch';
44
import { load } from 'cheerio';
55
import { parseDate } from '@/utils/parse-date';
6-
import timezone from '@/utils/timezone';
76

87
const url = 'https://news.shisu.edu.cn';
98
const banner = 'https://news.shisu.edu.cn/news/index/39adf3d9ae414bc39c6d3b9316ae531f.png';
109

1110
export const route: Route = {
12-
path: '/news/:category',
11+
path: '/news/:section',
1312
categories: ['university'],
14-
example: '/shisu/news/notice',
15-
parameters: { category: '新闻的分类可根据自己的需要选择,首页为全部新闻' },
13+
example: '/shisu/news/news',
14+
parameters: { section: '主站的新闻类别' },
1615
features: {
1716
requireConfig: false,
1817
requirePuppeteer: false,
@@ -23,20 +22,20 @@ export const route: Route = {
2322
},
2423
radar: [
2524
{
26-
source: ['news.shisu.edu.cn/:category/index.html'],
25+
source: ['news.shisu.edu.cn/:section/index.html'],
2726
},
2827
],
2928
name: '上外新闻',
3029
maintainers: ['Duuckjing'],
3130
handler,
3231
description: `| 首页 | 特稿 | 学术 | 教学 | 国际 | 校园 | 人物 | 视讯 | 公告 |
33-
| ---- | ------- | --------- | ---------- | ------------- | ------ | ------ | ---------- | ------ |
34-
| news | gazette | research- | academics- | international | campus | people | multimedia | notice |`,
32+
| ---- | ------- | --------- | ---------- | ------------- | ------ | ------ | ---------- | ------ |
33+
| news | gazette | research- | academics- | international | campus | people | multimedia | notice |`,
3534
};
3635

3736
async function handler(ctx) {
3837
const { section = 'news' } = ctx.req.param();
39-
const { data: r } = await got(`${url}/${section}/index.html`);
38+
const r = await ofetch(`${url}/${section}/index.html`);
4039
const $ = load(r);
4140
let itemsoup;
4241
switch (section) {
@@ -60,7 +59,7 @@ async function handler(ctx) {
6059
.map((i0) => {
6160
const i = $(i0);
6261
return {
63-
title: i.find('h3>a').attr('title').trim(),
62+
title: i.find('h3>a').attr('title')?.trim(),
6463
link: `${url}${i.find('h3>a').attr('href')}`,
6564
category: i.find('p>span:nth-child(1)').text(),
6665
};
@@ -69,12 +68,12 @@ async function handler(ctx) {
6968
const items = await Promise.all(
7069
itemsoup.map((j) =>
7170
cache.tryGet(j.link, async () => {
72-
const { data: r } = await got(j.link);
71+
const r = await ofetch(j.link);
7372
const $ = load(r);
7473
const img = $('.tempWrap > ul > li:nth-child(1)> img').attr('src');
7574
j.description = $('.ot_main_r .content').html();
7675
j.author = $('.math_time_l > span:nth-child(3)').text().trim();
77-
j.pubDate = timezone(parseDate($('.math_time_l > span:nth-child(2)').text(), 'YYYY-MM-DD'), +8);
76+
j.pubDate = parseDate($('.math_time_l > span:nth-child(2)').text(), 'YYYY-MM-DD');
7877
if (!j.itunes_item_image) {
7978
j.itunes_item_image = img ? `${url}${img}` : banner;
8079
}
@@ -85,7 +84,7 @@ async function handler(ctx) {
8584

8685
return {
8786
title: `上外新闻|SISU TODAY -${section.charAt(0).toUpperCase() + section.slice(1)}`,
88-
image: 'https://bkimg.cdn.bcebos.com/pic/8d5494eef01f3a296b70affa9825bc315c607c4d?x-bce-process=image/resize,m_lfit,w_536,limit_1/quality,Q_70',
87+
image: 'https://upload.wikimedia.org/wikipedia/zh/thumb/0/06/Shanghai_International_Studies_University_logo.svg/300px-Shanghai_International_Studies_University_logo.svg.png',
8988
link: `${url}/${section}/index.html`,
9089
item: items,
9190
};

0 commit comments

Comments
 (0)