fix(route): fixed the parameter section to shisu and add an English site. (#15625)
* fix(route):fixed the parameter section and add an english site. * fix(route): replaced got with ofetch of the English site. * Update en.ts * modified en.ts and news.ts --------- Co-authored-by: zmvw <iammcw@163.com>
This commit is contained in:
parent
acaf8dc411
commit
b259388acf
|
|
@ -0,0 +1,75 @@
|
|||
import { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
import { load } from 'cheerio';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
const url = 'http://en.shisu.edu.cn';
|
||||
const urlBackup = 'https://en.shisu.edu.cn';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/en/:section',
|
||||
categories: ['university'],
|
||||
example: '/shisu/en/news',
|
||||
parameters: { section: 'The name of resources' },
|
||||
radar: [
|
||||
{
|
||||
source: ['en.shisu.edu.cn/resources/:section/'],
|
||||
target: '/en/:section',
|
||||
},
|
||||
],
|
||||
name: 'SISU TODAY | FEATURED STORIES',
|
||||
maintainers: ['Duuckjing'],
|
||||
handler,
|
||||
description: `- features: Read a series of in-depth stories about SISU faculty, students, alumni and beyond campus.
|
||||
- news: SISU TODAY English site.`,
|
||||
};
|
||||
|
||||
async function process(baseUrl: string, section: any) {
|
||||
const r = await ofetch(`${baseUrl}/resources/${section}/`);
|
||||
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 = `${baseUrl}${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: `${baseUrl}${img}`,
|
||||
};
|
||||
});
|
||||
const items = await Promise.all(
|
||||
itemsoup.map((j) =>
|
||||
cache.tryGet(j.link, async () => {
|
||||
const r = await ofetch(j.link);
|
||||
const $ = load(r);
|
||||
j.description = $('.details-con')
|
||||
.html()!
|
||||
.replaceAll(/<o:p>[\S\s]*?<\/o:p>/g, '')
|
||||
.replaceAll(/(<p[^>]*> <\/p>\s*)+/gm, '<p> </p>');
|
||||
return j;
|
||||
})
|
||||
)
|
||||
);
|
||||
return {
|
||||
title: String(section) === 'features' ? 'FEATURED STORIES' : 'SISU TODAY',
|
||||
link: `${url}/resources/${section}/`,
|
||||
item: items,
|
||||
};
|
||||
}
|
||||
|
||||
async function handler(ctx) {
|
||||
const { section } = ctx.req.param();
|
||||
let res: any;
|
||||
try {
|
||||
await ofetch(url);
|
||||
res = process(url, section);
|
||||
} catch {
|
||||
await ofetch(urlBackup);
|
||||
res = process(urlBackup, section);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
@ -2,5 +2,5 @@ import type { Namespace } from '@/types';
|
|||
|
||||
export const namespace: Namespace = {
|
||||
name: '上海外国语大学',
|
||||
url: 'news.shisu.edu.cn',
|
||||
url: 'shisu.edu.cn',
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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,7 +22,8 @@ export const route: Route = {
|
|||
},
|
||||
radar: [
|
||||
{
|
||||
source: ['news.shisu.edu.cn/:category/index.html'],
|
||||
source: ['news.shisu.edu.cn/:section/index.html'],
|
||||
target: '/news/:section',
|
||||
},
|
||||
],
|
||||
name: '上外新闻',
|
||||
|
|
@ -36,7 +36,7 @@ export const route: Route = {
|
|||
|
||||
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 +60,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 +69,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;
|
||||
}
|
||||
|
|
@ -84,8 +84,8 @@ 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',
|
||||
title: `上外新闻|SISU TODAY - ${section.charAt(0).toUpperCase() + section.slice(1)}`,
|
||||
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,
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue