diff --git a/lib/routes/shisu/en.ts b/lib/routes/shisu/en.ts new file mode 100644 index 00000000000000..259ec2075b83d2 --- /dev/null +++ b/lib/routes/shisu/en.ts @@ -0,0 +1,61 @@ +import { Route } from '@/types'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import { got } from 'got'; +import cache from '@/utils/cache'; + +export const route: Route = { + path: '/en/features', + categories: ['university'], + example: '/shisu/en/features', + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['en.shisu.edu.cn/resources/features/'], + }, + ], + name: 'FEATURED STORIES', + maintainers: ['Duuckjing'], + description: 'Read a series of in-depth stories about SISU faculty, students, alumni and beyond campus.', + handler: async () => { + const url = 'https://en.shisu.edu.cn'; + const { body: r } = await got(`${url}/resources/features/`, { https: { rejectUnauthorized: false } }); + // eslint-disable-next-line no-console + const $ = load(r); + const itemsoup = $('.tab-con:nth-child(1) ul li') + .toArray() + .map((i0) => { + const i = $(i0); + const img = i.find('img').attr('src'); + const link = `${url}${i.find('h3>a').attr('href')}`; + return { + title: i.find('h3>a').text().trim(), + link, + pubDate: parseDate(i.find('p.time').text()), + itunes_item_image: `${url}${img}`, + }; + }); + const items = await Promise.all( + itemsoup.map((j) => + cache.tryGet(j.link, async () => { + const { body: r } = await got(j.link, { https: { rejectUnauthorized: false } }); + const $ = load(r); + j.description = $('.details-con').html()!; + return j; + }) + ) + ); + return { + title: 'FEATURED STORIES', + link: `${url}/resources/features/`, + item: items, + }; + }, +}; diff --git a/lib/routes/shisu/namespace.ts b/lib/routes/shisu/namespace.ts index e25ff24e13267b..5301f9b5cd1582 100644 --- a/lib/routes/shisu/namespace.ts +++ b/lib/routes/shisu/namespace.ts @@ -2,5 +2,5 @@ import type { Namespace } from '@/types'; export const namespace: Namespace = { name: '上海外国语大学', - url: 'news.shisu.edu.cn', + url: 'shisu.edu.cn', }; diff --git a/lib/routes/shisu/news.ts b/lib/routes/shisu/news.ts index 6fed5ae4201c22..0005358079b698 100644 --- a/lib/routes/shisu/news.ts +++ b/lib/routes/shisu/news.ts @@ -1,18 +1,17 @@ import { Route } from '@/types'; import cache from '@/utils/cache'; -import got from '@/utils/got'; +import ofetch from '@/utils/ofetch'; import { load } from 'cheerio'; import { parseDate } from '@/utils/parse-date'; -import timezone from '@/utils/timezone'; const url = 'https://news.shisu.edu.cn'; const banner = 'https://news.shisu.edu.cn/news/index/39adf3d9ae414bc39c6d3b9316ae531f.png'; export const route: Route = { - path: '/news/:category', + path: '/news/:section', categories: ['university'], - example: '/shisu/news/notice', - parameters: { category: '新闻的分类可根据自己的需要选择,首页为全部新闻' }, + example: '/shisu/news/news', + parameters: { section: '主站的新闻类别' }, features: { requireConfig: false, requirePuppeteer: false, @@ -23,20 +22,20 @@ export const route: Route = { }, radar: [ { - source: ['news.shisu.edu.cn/:category/index.html'], + source: ['news.shisu.edu.cn/:section/index.html'], }, ], name: '上外新闻', maintainers: ['Duuckjing'], handler, description: `| 首页 | 特稿 | 学术 | 教学 | 国际 | 校园 | 人物 | 视讯 | 公告 | - | ---- | ------- | --------- | ---------- | ------------- | ------ | ------ | ---------- | ------ | - | news | gazette | research- | academics- | international | campus | people | multimedia | notice |`, + | ---- | ------- | --------- | ---------- | ------------- | ------ | ------ | ---------- | ------ | + | news | gazette | research- | academics- | international | campus | people | multimedia | notice |`, }; async function handler(ctx) { const { section = 'news' } = ctx.req.param(); - const { data: r } = await got(`${url}/${section}/index.html`); + const r = await ofetch(`${url}/${section}/index.html`); const $ = load(r); let itemsoup; switch (section) { @@ -60,7 +59,7 @@ async function handler(ctx) { .map((i0) => { const i = $(i0); return { - title: i.find('h3>a').attr('title').trim(), + title: i.find('h3>a').attr('title')?.trim(), link: `${url}${i.find('h3>a').attr('href')}`, category: i.find('p>span:nth-child(1)').text(), }; @@ -69,12 +68,12 @@ async function handler(ctx) { const items = await Promise.all( itemsoup.map((j) => cache.tryGet(j.link, async () => { - const { data: r } = await got(j.link); + const r = await ofetch(j.link); const $ = load(r); const img = $('.tempWrap > ul > li:nth-child(1)> img').attr('src'); j.description = $('.ot_main_r .content').html(); j.author = $('.math_time_l > span:nth-child(3)').text().trim(); - j.pubDate = timezone(parseDate($('.math_time_l > span:nth-child(2)').text(), 'YYYY-MM-DD'), +8); + j.pubDate = parseDate($('.math_time_l > span:nth-child(2)').text(), 'YYYY-MM-DD'); if (!j.itunes_item_image) { j.itunes_item_image = img ? `${url}${img}` : banner; } @@ -85,7 +84,7 @@ async function handler(ctx) { return { title: `上外新闻|SISU TODAY -${section.charAt(0).toUpperCase() + section.slice(1)}`, - image: 'https://bkimg.cdn.bcebos.com/pic/8d5494eef01f3a296b70affa9825bc315c607c4d?x-bce-process=image/resize,m_lfit,w_536,limit_1/quality,Q_70', + image: 'https://upload.wikimedia.org/wikipedia/zh/thumb/0/06/Shanghai_International_Studies_University_logo.svg/300px-Shanghai_International_Studies_University_logo.svg.png', link: `${url}/${section}/index.html`, item: items, };