parent
0b0b211bf9
commit
8b2eb2cee6
|
|
@ -57,6 +57,12 @@ pageClass: routes
|
|||
|
||||
</Route>
|
||||
|
||||
## Engadget 瘾科技
|
||||
|
||||
### 中文全文
|
||||
|
||||
<Route author="JamesWDGu" example="/engadget-cn" path="/engadget-cn"/>
|
||||
|
||||
## iDownloadBlog
|
||||
|
||||
### blog
|
||||
|
|
|
|||
|
|
@ -1707,4 +1707,7 @@ router.get('/andyt/:view?', require('./routes/andyt/index'));
|
|||
// 品途商业评论
|
||||
router.get('/pintu360/:type?', require('./routes/pintu360/index'));
|
||||
|
||||
// engadget中国版
|
||||
router.get('/engadget-cn', require('./routes/engadget-cn/home'));
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const parser = require('@/utils/rss-parser');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const feed = await parser.parseURL('https://cn.engadget.com/rss.xml');
|
||||
|
||||
const ProcessFeed = (data) => {
|
||||
const $ = cheerio.load(data);
|
||||
return $.html('figure img') + '<br>' + $('.article-text p').html();
|
||||
};
|
||||
|
||||
const items = await Promise.all(
|
||||
feed.items.map(async (item) => {
|
||||
const cache = await ctx.cache.get(item.link);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
const description = ProcessFeed(response.data);
|
||||
const single = {
|
||||
title: item.title,
|
||||
description,
|
||||
pubDate: item.pubDate,
|
||||
link: item.link,
|
||||
author: item.author,
|
||||
};
|
||||
ctx.cache.set(item.link, JSON.stringify(single));
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: 'Engadget 中文版 全文',
|
||||
link: 'https://cn.engadget.com/',
|
||||
description: feed.description,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue