feat: add JustRun职业投资者阅读记录 (#5455)

This commit is contained in:
Ethan Shen 2020-08-21 05:11:17 +08:00 committed by GitHub
parent 06736938e2
commit b5e5003ae9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 0 deletions

View File

@ -58,6 +58,10 @@ pageClass: routes
<Route author="xyqfer" example="/leemeng" path="/leemeng"/>
## JustRun
<Route author="nczitzk" example="/justrun" path="/justrun"/>
## Paul Graham 博客
通过提取文章全文,提供比官方源更佳的阅读体验。

View File

@ -3081,4 +3081,7 @@ router.get('/souyun/today', require('./routes/souyun/today'));
// 生物谷
router.get('/bioon/latest', require('./routes/bioon/latest'));
// JustRun
router.get('/justrun', require('./routes/justrun/index'));
module.exports = router;

View File

@ -0,0 +1,45 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const currentUrl = 'http://justrun.thisistap.com/';
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('#main article header h2 a')
.slice(0, 10)
.map((_, item) => {
item = $(item);
return {
title: item.text(),
link: item.attr('href'),
};
})
.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,
});
const content = cheerio.load(detailResponse.data);
item.description = content('div.single-content').html();
item.pubDate = new Date(content('meta[property="article:published_time"]').attr('content')).toUTCString();
return item;
})
)
);
ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
};
};