feat(route): add OR (#7483)

This commit is contained in:
Ethan Shen 2021-05-15 11:06:58 +08:00 committed by GitHub
parent 09b438b94f
commit 2bc0d12019
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 0 deletions

View File

@ -463,6 +463,18 @@ IPFS 网关有可能失效,那时候换成其他网关。
</Route>
## OR
### 频道
<Route author="ncziztk" example="/or" path="/or/id?" :paramsDesc="['id见下表默认为首页']">
| 首页 | 商业 | 金融 | 政经 | 社会与文化 | 领导力 | 生活时尚 | 视频 |
| ---- | ---- | ----- | ---- | ---------- | ------ | -------- | ------ |
| | 7174 | 15176 | 8943 | 14910 | 11813 | 24138 | 324234 |
</Route>
## PMCAFF
### 今日推荐 / 精选

View File

@ -4081,4 +4081,7 @@ router.get('/bandcamp/tag/:tag?', require('./routes/bandcamp/tag'));
// Hugo 更新日志
router.get('/hugo/releases', require('./routes/hugo/releases'));
// OR
router.get('/or/:id?', require('./routes/or'));
module.exports = router;

55
lib/routes/or/index.js Normal file
View File

@ -0,0 +1,55 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const parseDate = require('@/utils/parse-date');
module.exports = async (ctx) => {
const id = ctx.params.id || '';
const rootUrl = 'https://www.or123.net';
const currentUrl = `${rootUrl}${id ? `/?page_id=${id}` : ''}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('.vc-carousel-slideline-inner')
.eq(0)
.find('.title')
.slice(0, 10)
.map((_, item) => {
item = $(item).parent();
return {
title: item.text(),
link: item.attr('href'),
};
})
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.description = content('.qfe_wrapper').eq(4).html();
item.pubDate = timezone(parseDate(detailResponse.data.match(/(\d{4}-\d{2}-\d{2} \d{2}:\d{2})/)[1], 'YYYY-MM-DD HH:mm'), +8);
return item;
})
)
);
ctx.state.data = {
title: `${$('.header_title').eq(0).text()} - OR`,
description: $('.header_subtitle').eq(0).text(),
link: currentUrl,
item: items,
};
};