feat: add 中国科学院青年创新促进会最新博文 (#6519)

This commit is contained in:
Ethan Shen
2020-12-26 05:49:08 +00:00
committed by GitHub
parent a28aebb0e2
commit c72f9d4bbf
3 changed files with 62 additions and 0 deletions
+6
View File
@@ -2032,6 +2032,12 @@ column 为 third 时可选的 category:
</Route>
## 中国科学院青年创新促进会
### 最新博文
<Route author="nczitzk" example="/yicas/blog" path="/yicas/blog"/>
## 中国劳工观察
### 调查报告
+3
View File
@@ -3744,6 +3744,9 @@ router.get('/idaily/today', require('./routes/idaily/index'));
// 北屋
router.get('/northhouse/:category?', require('./routes/northhouse/index'));
// 中国科学院青年创新促进会
router.get('/yicas/blog', require('./routes/yicas/blog'));
// 九三学社
router.get('/93/:category?', require('./routes/93/index'));
+53
View File
@@ -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,
};
};