增加:纽约时报-每日简报 (#1226)
This commit is contained in:
parent
04d192dd7c
commit
e0dea8fb80
|
|
@ -1690,6 +1690,8 @@ Category 列表:
|
|||
|
||||
</route>
|
||||
|
||||
<route name="每日简报" author="xyqfer" example="/nytimes/morning_post" path="/nytimes/morning_post"/>
|
||||
|
||||
### 新京报
|
||||
|
||||
<route name="栏目" author="DIYgod" example="/bjnews/realtime" path="/bjnews/:category" :paramsDesc="['新京报的栏目名, 点击对应栏目后在地址栏找到']"/>
|
||||
|
|
|
|||
|
|
@ -327,6 +327,7 @@ router.get('/yande.re/post/popular_recent/:period', require('./routes/yande.re/p
|
|||
|
||||
// 纽约时报
|
||||
router.get('/nytimes', require('./routes/nytimes/index'));
|
||||
router.get('/nytimes/morning_post', require('./routes/nytimes/morning_post'));
|
||||
|
||||
// 3dm
|
||||
router.get('/3dm/:name/:type', require('./routes/3dm/game'));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
const axios = require('../../utils/axios');
|
||||
const cheerio = require('cheerio');
|
||||
const utils = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const url = 'https://m.cn.nytimes.com/morning-brief/';
|
||||
const response = await axios({
|
||||
method: 'get',
|
||||
url,
|
||||
});
|
||||
const data = response.data;
|
||||
const $ = cheerio.load(data);
|
||||
const post = $('.article-list .regular-item')
|
||||
.map((index, elem) => {
|
||||
const $item = $(elem);
|
||||
const $link = $item.find('a');
|
||||
|
||||
return {
|
||||
title: $link.attr('title'),
|
||||
link: $link.attr('href'),
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
post.map(async (item) => {
|
||||
const link = item.link;
|
||||
const description = await ctx.cache.tryGet(`nyt: ${link}`, async () => {
|
||||
const response = await axios({
|
||||
method: 'get',
|
||||
url: link,
|
||||
});
|
||||
|
||||
return utils.ProcessFeed(response.data);
|
||||
});
|
||||
|
||||
item.description = description;
|
||||
return Promise.resolve(item);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '纽约时报 每日简报',
|
||||
link: url,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue