parent
98a41593db
commit
1c6411fcad
|
|
@ -1120,6 +1120,10 @@ area 分区选项
|
|||
|
||||
</Route>
|
||||
|
||||
## 全现在
|
||||
|
||||
<Route author="nczitzk" example="/allnow/column/199" path="/allnow/column/:id" :paramsDesc="['专栏 id']"/>
|
||||
|
||||
## 人人都是产品经理
|
||||
|
||||
### 热门文章
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue