Skip to content

Commit

Permalink
feat(route): add OR (DIYgod#7483)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan Shen authored May 15, 2021
1 parent 09b438b commit 2bc0d12
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
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 @@ -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 changes: 55 additions & 0 deletions lib/routes/or/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');
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,
};
};

0 comments on commit 2bc0d12

Please sign in to comment.