1
1
import { Route } from '@/types' ;
2
2
import cache from '@/utils/cache' ;
3
- import got from '@/utils/got ' ;
3
+ import ofetch from '@/utils/ofetch ' ;
4
4
import { load } from 'cheerio' ;
5
5
import { parseDate } from '@/utils/parse-date' ;
6
- import timezone from '@/utils/timezone' ;
7
6
8
7
const url = 'https://news.shisu.edu.cn' ;
9
8
const banner = 'https://news.shisu.edu.cn/news/index/39adf3d9ae414bc39c6d3b9316ae531f.png' ;
10
9
11
10
export const route : Route = {
12
- path : '/news/:category ' ,
11
+ path : '/news/:section ' ,
13
12
categories : [ 'university' ] ,
14
- example : '/shisu/news/notice ' ,
15
- parameters : { category : '新闻的分类可根据自己的需要选择,首页为全部新闻 ' } ,
13
+ example : '/shisu/news/news ' ,
14
+ parameters : { section : '主站的新闻类别 ' } ,
16
15
features : {
17
16
requireConfig : false ,
18
17
requirePuppeteer : false ,
@@ -23,20 +22,20 @@ export const route: Route = {
23
22
} ,
24
23
radar : [
25
24
{
26
- source : [ 'news.shisu.edu.cn/:category /index.html' ] ,
25
+ source : [ 'news.shisu.edu.cn/:section /index.html' ] ,
27
26
} ,
28
27
] ,
29
28
name : '上外新闻' ,
30
29
maintainers : [ 'Duuckjing' ] ,
31
30
handler,
32
31
description : `| 首页 | 特稿 | 学术 | 教学 | 国际 | 校园 | 人物 | 视讯 | 公告 |
33
- | ---- | ------- | --------- | ---------- | ------------- | ------ | ------ | ---------- | ------ |
34
- | news | gazette | research- | academics- | international | campus | people | multimedia | notice |` ,
32
+ | ---- | ------- | --------- | ---------- | ------------- | ------ | ------ | ---------- | ------ |
33
+ | news | gazette | research- | academics- | international | campus | people | multimedia | notice |` ,
35
34
} ;
36
35
37
36
async function handler ( ctx ) {
38
37
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` ) ;
40
39
const $ = load ( r ) ;
41
40
let itemsoup ;
42
41
switch ( section ) {
@@ -60,7 +59,7 @@ async function handler(ctx) {
60
59
. map ( ( i0 ) => {
61
60
const i = $ ( i0 ) ;
62
61
return {
63
- title : i . find ( 'h3>a' ) . attr ( 'title' ) . trim ( ) ,
62
+ title : i . find ( 'h3>a' ) . attr ( 'title' ) ? .trim ( ) ,
64
63
link : `${ url } ${ i . find ( 'h3>a' ) . attr ( 'href' ) } ` ,
65
64
category : i . find ( 'p>span:nth-child(1)' ) . text ( ) ,
66
65
} ;
@@ -69,12 +68,12 @@ async function handler(ctx) {
69
68
const items = await Promise . all (
70
69
itemsoup . map ( ( j ) =>
71
70
cache . tryGet ( j . link , async ( ) => {
72
- const { data : r } = await got ( j . link ) ;
71
+ const r = await ofetch ( j . link ) ;
73
72
const $ = load ( r ) ;
74
73
const img = $ ( '.tempWrap > ul > li:nth-child(1)> img' ) . attr ( 'src' ) ;
75
74
j . description = $ ( '.ot_main_r .content' ) . html ( ) ;
76
75
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' ) ;
78
77
if ( ! j . itunes_item_image ) {
79
78
j . itunes_item_image = img ? `${ url } ${ img } ` : banner ;
80
79
}
@@ -85,7 +84,7 @@ async function handler(ctx) {
85
84
86
85
return {
87
86
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 ' ,
89
88
link : `${ url } /${ section } /index.html` ,
90
89
item : items ,
91
90
} ;
0 commit comments