route: add DoNews (#1585)
This commit is contained in:
parent
a118a56615
commit
072f14354a
|
|
@ -2955,7 +2955,7 @@ board 和 build 可在[这里](http://api.ineal.me/tss/status)查看
|
|||
|
||||
### 惠誉评级
|
||||
|
||||
<route name="板块信息" author="LogicJake" example="/fitchratings/site/economics" path="/fitchratings/site/:type" :paramsDesc="['板块名称,在网址site后面']"/>
|
||||
<route name="板块信息" author="LogicJake" example="/fitchratings/site/economics" path="/fitchratings/site/:type" :paramsDesc="['板块名称,在网址 site 后面']"/>
|
||||
|
||||
### 移动支付网
|
||||
|
||||
|
|
@ -2975,9 +2975,9 @@ board 和 build 可在[这里](http://api.ineal.me/tss/status)查看
|
|||
|
||||
### 人人都是产品经理
|
||||
|
||||
<route name="用户收藏" author="LogicJake" example="/woshipm/bookmarks/324696" path="/woshipm/bookmarks/:id" :paramsDesc="['用户id']"/>
|
||||
<route name="用户收藏" author="LogicJake" example="/woshipm/bookmarks/324696" path="/woshipm/bookmarks/:id" :paramsDesc="['用户 id']"/>
|
||||
|
||||
<route name="用户文章" author="LogicJake" example="/woshipm/user_article/324696" path="/woshipm/user_article/:id" :paramsDesc="['用户id']"/>
|
||||
<route name="用户文章" author="LogicJake" example="/woshipm/user_article/324696" path="/woshipm/user_article/:id" :paramsDesc="['用户 id']"/>
|
||||
|
||||
### 鲸跃汽车
|
||||
|
||||
|
|
@ -2986,3 +2986,13 @@ board 和 build 可在[这里](http://api.ineal.me/tss/status)查看
|
|||
### 每日安全
|
||||
|
||||
<route name="推送" author="LogicJake" example="/security/pulses" path="/security/pulses"/>
|
||||
|
||||
### DoNews
|
||||
|
||||
<route name="栏目" author="HenryQW" example="/donews" path="/donews/:column?" :paramsDesc="['栏目代码, 默认为首页.']">
|
||||
|
||||
| 首页 | 商业 | 创业 | 互娱 | 科技 | 专栏 |
|
||||
| ---- | ------- | -------- | ---- | ---------- | ------- |
|
||||
| (空) | company | business | ent | technology | idonews |
|
||||
|
||||
</route>
|
||||
|
|
|
|||
|
|
@ -1071,4 +1071,7 @@ router.get('/nowcoder/discuss/:type/:order', require('./routes/nowcoder/discuss'
|
|||
// 每日安全
|
||||
router.get('/security/pulses', require('./routes/security/pulses'));
|
||||
|
||||
// DoNews
|
||||
router.get('/donews/:column?', require('./routes/donews/index'));
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,70 @@
|
|||
const axios = require('../../utils/axios');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const util = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { column = '' } = ctx.params;
|
||||
|
||||
let host = `http://www.donews.com/${column}`;
|
||||
|
||||
if (column !== '' && column !== 'idonews') {
|
||||
host += '/index';
|
||||
}
|
||||
|
||||
const response = await axios.get(host);
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
let list,
|
||||
title = 'DoNews - ';
|
||||
|
||||
if (column === '') {
|
||||
title += '首页';
|
||||
} else {
|
||||
title += $('.breadCrumb > a:nth-child(2)').text();
|
||||
}
|
||||
|
||||
switch (column) {
|
||||
case '':
|
||||
// 首页轮播
|
||||
list = $('.focues.hide > ul > li > a').get();
|
||||
list = list.concat(
|
||||
$('.fl.w840 > .block > dl > dd > h3 > a')
|
||||
.slice(0, 7)
|
||||
.get()
|
||||
);
|
||||
|
||||
break;
|
||||
case 'ent':
|
||||
case 'idonews':
|
||||
// 首页轮播
|
||||
list = $('ul.zl-top > li > a').get();
|
||||
list = list.concat(
|
||||
$('.fl.w840 > .block > dl > dd > h3 > a')
|
||||
.slice(0, 5)
|
||||
.get()
|
||||
);
|
||||
|
||||
break;
|
||||
default:
|
||||
list = $('.fl.w840 > .block > dl > dd > h3 > a')
|
||||
.slice(0, 10)
|
||||
.get();
|
||||
break;
|
||||
}
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(async (e) => {
|
||||
const link = $(e).attr('href');
|
||||
return await ctx.cache.tryGet(link, async () => await util.ProcessFeed(link));
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title,
|
||||
link: host,
|
||||
description: '中国最早的web2.0网站,专业科技媒体、互联网行业门户网站。提供互联网新闻IT资讯,关注科技创新,覆盖移动互联网创业、游戏、风险投资等热点,是中国互联网行业的风向标。',
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
const cheerio = require('cheerio');
|
||||
const axios = require('../../utils/axios');
|
||||
const date = require('../../utils/date');
|
||||
|
||||
const ProcessFeed = async (link) => {
|
||||
const response = await axios.get(link);
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const meta = $($('#main .fl')[0]);
|
||||
|
||||
return {
|
||||
title: $('h1').text() || $($('h2')[1]).text(),
|
||||
author: meta.find('span:nth-child(1)').text(),
|
||||
description: $('.article-con').html(),
|
||||
pubDate: date(meta.find('span:nth-child(2)').text(), 8),
|
||||
link,
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
ProcessFeed,
|
||||
};
|
||||
Loading…
Reference in New Issue