diff --git a/docs/new-media.md b/docs/new-media.md index 66f591d73..4edea5df0 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -57,6 +57,12 @@ pageClass: routes +## Engadget 瘾科技 + +### 中文全文 + + + ## iDownloadBlog ### blog diff --git a/lib/router.js b/lib/router.js index 229e3d8b1..8689e4cf6 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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; diff --git a/lib/routes/engadget-cn/home.js b/lib/routes/engadget-cn/home.js new file mode 100644 index 000000000..8ac85bd3b --- /dev/null +++ b/lib/routes/engadget-cn/home.js @@ -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') + '
' + $('.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, + }; +};