-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add 长江大学动物科学学院 (#12795)
- Loading branch information
Showing
5 changed files
with
100 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
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,60 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const timezone = require('@/utils/timezone'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
|
||
module.exports = async (ctx) => { | ||
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 10; | ||
|
||
const rootUrl = 'https://dongke.yangtzeu.edu.cn'; | ||
const currentUrl = new URL(`${ctx.path.replace(/^\/dongke/, '') || '/yqzl/xyxw'}.htm`, rootUrl).href; | ||
|
||
const { data: response } = await got(currentUrl); | ||
|
||
const $ = cheerio.load(response); | ||
|
||
let items = $('ul.list-item li a') | ||
.slice(0, limit) | ||
.toArray() | ||
.map((item) => { | ||
item = $(item); | ||
|
||
return { | ||
title: item.text(), | ||
link: new URL(item.prop('href'), rootUrl).href, | ||
}; | ||
}); | ||
|
||
items = await Promise.all( | ||
items.map((item) => | ||
ctx.cache.tryGet(item.link, async () => { | ||
const { data: detailResponse } = await got(item.link); | ||
|
||
const content = cheerio.load(detailResponse); | ||
|
||
item.title = content('title').text(); | ||
item.description = content('div.v_news_content').html(); | ||
item.category = content('meta[name="keywords"]').prop('content').split(','); | ||
item.pubDate = timezone( | ||
parseDate( | ||
content('p.content-info') | ||
.text() | ||
.match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/)[1] | ||
), | ||
+8 | ||
); | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
ctx.state.data = { | ||
item: items, | ||
title: $('title').text(), | ||
link: currentUrl, | ||
language: 'zh-cn', | ||
image: new URL($('#head-img a img').prop('src'), rootUrl).href, | ||
author: '长江大学动物科学学院', | ||
}; | ||
}; |
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 = { | ||
'/dongke/:path+': ['nczitzk'], | ||
}; |
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,18 @@ | ||
module.exports = { | ||
'yangtzeu.edu.cn': { | ||
_name: '长江大学', | ||
'.': [ | ||
{ | ||
title: '动物科学学院', | ||
docs: 'https://docs.rsshub.app/universities.html#chang-jiang-da-xue-dong-wu-ke-xue-xue-yuan', | ||
source: ['/:category', '/'], | ||
target: (params, url) => { | ||
url = new URL(url); | ||
const path = /\.edu\.cn(.*?)\.htm/.test(url.href) ? url.href.match(/\.edu\.cn(.*?)\.htm/)[1] : ''; | ||
|
||
return `/yangtzeu/dongke${path}`; | ||
}, | ||
}, | ||
], | ||
}, | ||
}; |
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 = function (router) { | ||
router.get(/dongke([\w-/]+)?/, require('./dongke')); | ||
}; |