feat: 增加生物谷 (#4862)

This commit is contained in:
xfangbao
2020-06-01 00:16:24 -04:00
committed by GitHub
parent 09369894f8
commit 858a84a69c
3 changed files with 56 additions and 0 deletions

View File

@@ -259,3 +259,15 @@ count 的取值范围为 1-12为防止请求次数过多推荐设置为 5
### 主页
<Route author="kt286" example="/zreading" path="/zreading" />
## 生物谷
### 所有栏目
<Route author="xfangbao" example="/shengwugu/biology" path="/shengwugu/:uid/" :paramsDesc="['分栏代码, 可在 URL 找到']" />
具体栏目编号,去网站上看标签
| 网址 | 对应路由 |
| -------- | -------- |
| http://news.bioon.com/biology | /shengwugu/biology |

View File

@@ -2772,6 +2772,9 @@ router.get('/zhutix/latest', require('./routes/zhutix/latest'));
// arXiv
router.get('/arxiv/:query', require('./routes/arxiv/query'));
// 生物谷
router.get('/shengwugu/:uid?', require('./routes/shengwugu/index'));
// 环球律师事务所文章
router.get('/law/hq', require('./routes/law/hq'));

View File

@@ -0,0 +1,41 @@
const cheerio = require('cheerio');
const got = require('@/utils/got');
module.exports = async (ctx) => {
const url = `http://news.bioon.com/${ctx.params.uid}`;
const res = await got.get(url);
const $ = cheerio.load(res.data);
const list = $('.cntx').get();
const out = await Promise.all(
list.slice(0, 3).map(async (item) => {
const $ = cheerio.load(item);
const title = $('.cntx h4 a').text();
const partial = $('.cntx h4 a').attr('href');
const address = partial;
const time = $('.fl huise').text();
const cache = await ctx.cache.get(address);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const res = await got.get(address);
const get = cheerio.load(res.data);
const contents = get('.text3').html();
const single = {
title,
pubDate: time,
description: contents,
link: address,
guid: address,
};
ctx.cache.set(address, JSON.stringify(single));
return Promise.resolve(single);
})
);
ctx.state.data = {
title: $('title').text(),
link: url,
item: out,
};
};