forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add 中国科学院青年创新促进会最新博文 (DIYgod#6519)
- Loading branch information
Ethan Shen
authored
Dec 26, 2020
1 parent
a28aebb
commit c72f9d4
Showing
3 changed files
with
62 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
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,53 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const iconv = require('iconv-lite'); | ||
|
||
module.exports = async (ctx) => { | ||
const rootUrl = 'http://yicas.cn'; | ||
const currentUrl = `${rootUrl}/portal.php?mod=blog`; | ||
const response = await got({ | ||
method: 'get', | ||
url: currentUrl, | ||
responseType: 'buffer', | ||
}); | ||
|
||
const $ = cheerio.load(iconv.decode(response.data, 'gbk')); | ||
|
||
const list = $('tr td a[title]') | ||
.slice(0, 15) | ||
.map((_, item) => { | ||
item = $(item); | ||
return { | ||
title: item.text(), | ||
link: item.attr('href'), | ||
pubDate: new Date(item.next().text()).toUTCString(), | ||
}; | ||
}) | ||
.get(); | ||
|
||
const items = await Promise.all( | ||
list.map( | ||
async (item) => | ||
await ctx.cache.tryGet(item.link, async () => { | ||
const detailResponse = await got({ | ||
method: 'get', | ||
url: item.link, | ||
responseType: 'buffer', | ||
}); | ||
const content = cheerio.load(iconv.decode(detailResponse.data, 'gbk')); | ||
|
||
item.author = content('.xs2').text(); | ||
item.description = content('#blog_article').html(); | ||
item.pubDate = new Date(content('.xg1').eq(5).text()).toUTCString(); | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
ctx.state.data = { | ||
title: $('title').text(), | ||
link: currentUrl, | ||
item: items, | ||
}; | ||
}; |