diff --git a/docs/README.md b/docs/README.md index 324304f17..474401c6a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2805,3 +2805,7 @@ board 和 build 可在[这里](http://api.ineal.me/tss/status)查看 ### 多抓鱼 + +### 创业邦 + + diff --git a/lib/router.js b/lib/router.js index d37fc8d4d..a853219b7 100644 --- a/lib/router.js +++ b/lib/router.js @@ -995,4 +995,7 @@ router.get('/wallstreetcn/news/global', require('./routes/wallstreetcn/news')); // 多抓鱼搜索 router.get('/duozhuayu/search/:wd', require('./routes/duozhuayu/search')); +// 创业邦 +router.get('/cyzone/author/:id', require('./routes/cyzone/author')); + module.exports = router; diff --git a/lib/routes/cyzone/author.js b/lib/routes/cyzone/author.js new file mode 100644 index 000000000..cc0e2e049 --- /dev/null +++ b/lib/routes/cyzone/author.js @@ -0,0 +1,56 @@ +const cheerio = require('cheerio'); +const axios = require('../../utils/axios'); + +module.exports = async (ctx) => { + const { id } = ctx.params; + const url = `https://www.cyzone.cn/author/${id}`; + const res = await axios.get(url); + const data = res.data; + const $ = cheerio.load(data); + + const list = $('.article-item'); + + const out = await Promise.all( + list + .map(async (index, elem) => { + const $elem = $(elem); + const $title = $elem.find('.item-title'); + const link = 'https:' + $title.attr('href'); + const pubDate = new Date(+$elem.find('.time').attr('data-time') * 1000).toUTCString(); + const item = { + title: $title.text(), + pubDate, + link, + }; + const key = `cyzone-${link}`; + const value = await ctx.cache.get(key); + if (value) { + item.description = value; + } else { + const storyDetail = await axios.get(item.link); + const data = storyDetail.data; + const $ = cheerio.load(data); + $('.article-content img').each(function() { + const $img = $(this); + const src = $img.attr('src'); + + if (!src.startsWith('http')) { + $img.attr('src', 'https:' + src); + } + }); + item.description = $('.article-content').html(); + ctx.cache.set(key, item.description, 12 * 60 * 60); + } + + return Promise.resolve(item); + }) + .get() + ); + + ctx.state.data = { + title: `创业邦-作者 ${$('.ss-title').text()}`, + link: url, + description: '创业邦致力于成为中国创业者的信息平台和服务平台,帮助中国创业者实现创业梦想。创业邦为创业者和风险投资人提供各种创业类最新资讯和实用知识手册,打造创业者和投资人的社交平台。', + item: out, + }; +};