feat: add chuapp.com (#6261)
This commit is contained in:
parent
2b417516d6
commit
4612bc8e4d
|
|
@ -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
|
||||
|
||||
### 新闻
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue