Skip to content

Commit

Permalink
fix(route):fixed the parameter section and add an
Browse files Browse the repository at this point in the history
english site.
  • Loading branch information
zmvw committed May 18, 2024
1 parent 70c4fe9 commit 3face66
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 14 deletions.
61 changes: 61 additions & 0 deletions lib/routes/shisu/en.ts
Original file line number Diff line number Diff line change
@@ -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,
};
},
};
2 changes: 1 addition & 1 deletion lib/routes/shisu/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: '上海外国语大学',
url: 'news.shisu.edu.cn',
url: 'shisu.edu.cn',
};
25 changes: 12 additions & 13 deletions lib/routes/shisu/news.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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) {
Expand All @@ -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(),
};
Expand All @@ -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;
}
Expand All @@ -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,
};
Expand Down

0 comments on commit 3face66

Please sign in to comment.