Skip to content

Commit

Permalink
feat: add chuapp.com (DIYgod#6261)
Browse files Browse the repository at this point in the history
  • Loading branch information
laampui authored Nov 30, 2020
1 parent 2b41751 commit 4612bc8
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/game.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,15 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的

</Route>

## 触乐

<Route author="laampui" example="/chuapp/index/daily" path="/chuapp/index/:category?" :paramsDesc="['默认为 night']">

| 每日聚焦 | 最好玩 | 触乐夜话 | 动态资讯 |
| -------- | ------ | -------- | -------- |
| daily | pcz | night | news |

</Route>
## 二柄 APP

### 新闻
Expand Down
3 changes: 3 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down
55 changes: 55 additions & 0 deletions lib/routes/chuapp/index.js
Original file line number Diff line number Diff line change
@@ -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,
};
};

0 comments on commit 4612bc8

Please sign in to comment.