feat(route): add OR (#7483)
This commit is contained in:
parent
09b438b94f
commit
2bc0d12019
|
|
@ -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
|
||||
|
||||
### 今日推荐 / 精选
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue