diff --git a/docs/bbs.md b/docs/bbs.md index fa0deaa51..a80134400 100644 --- a/docs/bbs.md +++ b/docs/bbs.md @@ -337,6 +337,12 @@ pageClass: routes +## 万维读者 + +### 焦点新闻 + + + ## 小米社区 ### 圈子 diff --git a/lib/router.js b/lib/router.js index a462b163c..684c9457b 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2932,6 +2932,9 @@ router.get('/gelonghui/keyword/:keyword', require('./routes/gelonghui/keyword')) // 光谷社区 router.get('/guanggoo/:caty', require('./routes/guanggoo/index')); +// 万维读者 +router.get('/creaders/headline', require('./routes/creaders/headline')); + // 金山词霸 router.get('/iciba/:days?/:img_type?', require('./routes/iciba/index')); diff --git a/lib/routes/creaders/headline.js b/lib/routes/creaders/headline.js new file mode 100644 index 000000000..c56cd591a --- /dev/null +++ b/lib/routes/creaders/headline.js @@ -0,0 +1,46 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); + +module.exports = async (ctx) => { + const currentUrl = 'http://news.creaders.net/headline/'; + const response = await got({ + method: 'get', + url: currentUrl, + }); + const $ = cheerio.load(iconv.decode(response.data, 'gbk')); + const list = $('ul.newslist li') + .slice(0, 10) + .map((_, item) => { + item = $(item); + const a = item.find('a').eq(1); + return { + title: a.text(), + link: a.attr('href'), + pubDate: new Date(item.find('time').text() + ' GMT+8').toUTCString(), + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const res = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(iconv.decode(res.data, 'gbk')); + + item.description = content('#newsContent').html(); + return item; + }) + ) + ); + + ctx.state.data = { + title: '万维读者 - 焦点新闻', + link: currentUrl, + item: items, + }; +};