feat: add 全现在专栏 (#5871)

Co-authored-by: Henry Wang <hi@henry.wang>
This commit is contained in:
Ethan Shen 2020-10-18 09:56:26 +08:00 committed by GitHub
parent 98a41593db
commit 1c6411fcad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 0 deletions

View File

@ -1120,6 +1120,10 @@ area 分区选项
</Route>
## 全现在
<Route author="nczitzk" example="/allnow/column/199" path="/allnow/column/:id" :paramsDesc="['专栏 id']"/>
## 人人都是产品经理
### 热门文章

View File

@ -3347,6 +3347,9 @@ router.get('/yuanshen/:location?/:category?', require('./routes/yuanshen/index')
// World Trade Organization
router.get('/wto/dispute-settlement/:year?', require('./routes/wto/dispute-settlement'));
// 全现在
router.get('/allnow/column/:id', require('./routes/allnow/column'));
// 证券时报网
router.get('/stcn/news/:id?', require('./routes/stcn/news'));

View File

@ -0,0 +1,49 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const rootUrl = 'https://m.allnow.com';
const currentUrl = `${rootUrl}/column/${ctx.params.id}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('a.normal')
.slice(0, 10)
.map((_, item) => {
item = $(item);
return {
link: `${rootUrl}${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.title = content('p.title').text();
item.author = content('a.single-name').eq(0).text();
item.description = content('#article-content').html();
item.pubDate = new Date(detailResponse.data.match(/time:"(.*)",abstract:"/)[1] + ' GMT+8').toUTCString();
return item;
})
)
);
ctx.state.data = {
title: `${$('p.name').text()} - 全现在`,
link: rootUrl,
item: items,
description: $('p.desc').text(),
};
};