Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): add OR #7483

Merged
merged 2 commits into from
May 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/new-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

### 今日推荐 / 精选
Expand Down
3 changes: 3 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -4061,4 +4061,7 @@ router.get('/jisilu/topic/:user', require('./routes/jisilu/topic'));
// Constitutional Court of Baden-Württemberg (Germany)
router.get('/verfghbw/press/:keyword?', require('./routes/verfghbw/press'));

// OR
router.get('/or/:id?', require('./routes/or'));

module.exports = router;
54 changes: 54 additions & 0 deletions lib/routes/or/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const date = require('@/utils/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 = date(detailResponse.data.match(/(\d{4}-\d{2}-\d{2} \d{2}:\d{2})/)[1]);

return item;
})
)
);

ctx.state.data = {
title: `${$('.header_title').eq(0).text()} - OR`,
description: $('.header_subtitle').eq(0).text(),
link: currentUrl,
item: items,
};
};