diff --git a/docs/game.md b/docs/game.md index 3fb1f2c6d..71b208924 100644 --- a/docs/game.md +++ b/docs/game.md @@ -322,6 +322,15 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的 +## 触乐 + + + +| 每日聚焦 | 最好玩 | 触乐夜话 | 动态资讯 | +| -------- | ------ | -------- | -------- | +| daily | pcz | night | news | + + ## 二柄 APP ### 新闻 diff --git a/lib/router.js b/lib/router.js index b13123ca9..fa2486bcb 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3576,6 +3576,9 @@ router.get('/youdao/latest', require('./routes/youdao/latest')); router.get('/yinxiang/note', require('./routes/yinxiang/note')); router.get('/yinxiang/card/:id?', require('./routes/yinxiang/card')); +// 触乐 +router.get('/chuapp/index/:category?', require('./routes/chuapp/index')); + // Deloitte router.get('/deloitte/industries/:category?', require('./routes/deloitte/industries')); diff --git a/lib/routes/chuapp/index.js b/lib/routes/chuapp/index.js new file mode 100644 index 000000000..164258696 --- /dev/null +++ b/lib/routes/chuapp/index.js @@ -0,0 +1,55 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const category = ctx.params.category || 'night'; + + const options = { + daily: { + title: '每日聚焦', + suffix: '/category/daily', + }, + pcz: { + title: '最好玩', + suffix: '/category/pcz', + }, + night: { + title: '触乐夜话', + suffix: '/tag/index/id/20369.html', + }, + news: { + title: '动态资讯', + suffix: '/category/zsyx', + }, + }; + + const response = await got.get(`https://www.chuapp.com${options[category].suffix}`); + const $ = cheerio.load(response.data); + + const articles = $('a.fn-clear') + .map((index, ele) => ({ + title: $(ele).attr('title'), + link: $(ele).attr('href'), + })) + .get(); + + const item = await Promise.all( + articles.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const res = await got.get(`http://www.chuapp.com${item.link}`); + const s = cheerio.load(res.data); + item.description = s('.content .the-content').html(); + item.pubDate = new Date(s('.friendly_time').attr('data-time')); + item.author = s('.author-time .fn-left').text(); + return Promise.resolve(item); + }) + ) + ); + + ctx.state.data = { + title: `触乐 - ${options[category].title}`, + link: `https://www.chuapp.com${options[category].suffix}`, + item, + }; +};