-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
const timezone = require('@/utils/timezone'); | ||
|
||
module.exports = async (ctx) => { | ||
const { listId } = ctx.params; | ||
const baseUrl = 'https://jwc.sspu.edu.cn'; | ||
|
||
const { data: response, url: link } = await got(`${baseUrl}/${listId}/list.htm`); | ||
const $ = cheerio.load(response); | ||
|
||
const list = $('.news_list .news') | ||
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 15) | ||
.toArray() | ||
.map((item) => { | ||
item = $(item); | ||
const title = item.find('.news_title a'); | ||
return { | ||
title: title.attr('title'), | ||
link: `${baseUrl}${title.attr('href')}`, | ||
}; | ||
}); | ||
|
||
const items = await Promise.all( | ||
list.map((item) => | ||
ctx.cache.tryGet(item.link, async () => { | ||
const { data: response } = await got(item.link); | ||
const $ = cheerio.load(response); | ||
|
||
item.description = $('.wp_articlecontent').html(); | ||
item.pubDate = timezone(parseDate($('.arti_update').text(), 'YYYY-MM-DD HH:mm:ss'), +8); | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
ctx.state.data = { | ||
title: $('head title').text(), | ||
link, | ||
item: items, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
'/jwc/:listId': ['TonyRL'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
'sspu.edu.cn': { | ||
_name: '上海第二工业大学', | ||
jwc: [ | ||
{ | ||
title: '教务处', | ||
docs: 'https://docs.rsshub.app/university#shang-hai-di-er-gong-ye-da-xue', | ||
source: ['/jwc/:listId/list.htm'], | ||
target: '/sspu/jwc/:listId', | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = (router) => { | ||
router.get('/jwc/:listId', require('./jwc')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters