feat: add benedictevans (#6066)
This commit is contained in:
parent
7d1da3b142
commit
c5a89f78c6
|
|
@ -10,6 +10,10 @@ pageClass: routes
|
|||
|
||||
<Route author="kt286" example="/archdaily" path="/archdaily"/>
|
||||
|
||||
## Benedict Evans
|
||||
|
||||
<Route author="emdoe" example="/benedictevans" path="/benedictevans"/>
|
||||
|
||||
## Google Sites
|
||||
|
||||
### 文章更新
|
||||
|
|
|
|||
|
|
@ -48,6 +48,9 @@ router.get('/quicker/update', require('./routes/quicker/update.js'));
|
|||
router.get('/quicker/user/action/:uid/:person', require('./routes/quicker/person.js'));
|
||||
router.get('/quicker/user/:uid/:person', require('./routes/quicker/person.js'));
|
||||
|
||||
// Benedict Evans
|
||||
router.get('/benedictevans', require('./routes/benedictevans/recent.js'));
|
||||
|
||||
// bilibili
|
||||
router.get('/bilibili/user/video/:uid/:disableEmbed?', require('./routes/bilibili/video'));
|
||||
router.get('/bilibili/user/article/:uid', require('./routes/bilibili/article'));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
const cheerio = require('cheerio');
|
||||
const got = require('@/utils/got');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const url = `https://www.ben-evans.com/benedictevans/`;
|
||||
|
||||
const res = await got.get(url);
|
||||
const $ = cheerio.load(res.data);
|
||||
const list = $('section > article').get();
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map(async (item) => {
|
||||
const $ = cheerio.load(item);
|
||||
const title = $('.BlogList-item-title').text();
|
||||
const address = 'https://www.ben-evans.com' + $('.BlogList-item-title').attr('href');
|
||||
const time = $('.Blog-meta-item--date').text();
|
||||
const cache = await ctx.cache.get(address);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
const res = await got.get(address);
|
||||
const capture = cheerio.load(res.data);
|
||||
const contents = capture('.col.sqs-col-12.span-12').html();
|
||||
const single = {
|
||||
title: title,
|
||||
author: 'Benedict Evans',
|
||||
description: contents,
|
||||
link: address,
|
||||
guid: address,
|
||||
pubDate: new Date(time).toUTCString(),
|
||||
};
|
||||
ctx.cache.set(address, JSON.stringify(single));
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
ctx.state.data = {
|
||||
title: `Benedict Evans`,
|
||||
link: url,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue