@@ -329,6 +329,8 @@ board 和 build 可在[这里](http://api.ineal.me/tss/status)查看
|
||||
|
||||
<Route name="作者" author="xyqfer" example="/cyzone/author/1225562" path="/cyzone/author/:id" :paramsDesc="['作者 id']"/>
|
||||
|
||||
<Route name="标签" author="LogicJake" example="/cyzone/label/创业邦周报" path="/cyzone/label/:name" :paramsDesc="['标签名称']"/>
|
||||
|
||||
## 惠誉评级
|
||||
|
||||
<Route name="板块信息" author="LogicJake" example="/fitchratings/site/economics" path="/fitchratings/site/:type" :paramsDesc="['板块名称,在网址 site 后面']"/>
|
||||
|
||||
@@ -1047,6 +1047,7 @@ router.get('/duozhuayu/search/:wd', require('./routes/duozhuayu/search'));
|
||||
|
||||
// 创业邦
|
||||
router.get('/cyzone/author/:id', require('./routes/cyzone/author'));
|
||||
router.get('/cyzone/label/:name', require('./routes/cyzone/label'));
|
||||
|
||||
// 政府
|
||||
router.get('/gov/zhengce/zuixin', require('./routes/gov/zhengce/zuixin'));
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
const cheerio = require('cheerio');
|
||||
const axios = require('../../utils/axios');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const name = ctx.params.name;
|
||||
const url = `https://www.cyzone.cn/label/${encodeURIComponent(name)}/`;
|
||||
const res = await axios.get(url);
|
||||
const $ = cheerio.load(res.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: `创业邦-#${name}#`,
|
||||
link: url,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user