diff --git a/docs/new-media.md b/docs/new-media.md index 517115a45782d4..2d6f6acd17cbcb 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -463,6 +463,18 @@ IPFS 网关有可能失效,那时候换成其他网关。 +## OR + +### 频道 + + + +| 首页 | 商业 | 金融 | 政经 | 社会与文化 | 领导力 | 生活时尚 | 视频 | +| ---- | ---- | ----- | ---- | ---------- | ------ | -------- | ------ | +| | 7174 | 15176 | 8943 | 14910 | 11813 | 24138 | 324234 | + + + ## PMCAFF ### 今日推荐 / 精选 diff --git a/lib/router.js b/lib/router.js index 8e7256c301c98f..0219fd5d0f18a2 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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; diff --git a/lib/routes/or/index.js b/lib/routes/or/index.js new file mode 100644 index 00000000000000..968b536c54fd66 --- /dev/null +++ b/lib/routes/or/index.js @@ -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, + }; +};