feat(route): add 全现在首页 & 话题 & 用户 (#7066)
This commit is contained in:
parent
945d7c03ed
commit
9b9a9d8c99
|
|
@ -1682,8 +1682,18 @@ column 为 third 时可选的 category:
|
|||
|
||||
## 全现在
|
||||
|
||||
### 专栏
|
||||
|
||||
<Route author="nczitzk" example="/allnow/column/199" path="/allnow/column/:id" :paramsDesc="['专栏 id']"/>
|
||||
|
||||
### 话题
|
||||
|
||||
<Route author="nczitzk" example="/allnow/tag/678" path="/allnow/tag/:id" :paramsDesc="['话题 id']"/>
|
||||
|
||||
### 用户
|
||||
|
||||
<Route author="nczitzk" example="/allnow/user/1891141" path="/allnow/user/:id" :paramsDesc="['用户 id']"/>
|
||||
|
||||
## 人人都是产品经理
|
||||
|
||||
### 热门文章
|
||||
|
|
|
|||
|
|
@ -3474,6 +3474,9 @@ router.get('/nudt/yjszs/:id?', require('./routes/universities/nudt/yjszs'));
|
|||
|
||||
// 全现在
|
||||
router.get('/allnow/column/:id', require('./routes/allnow/column'));
|
||||
router.get('/allnow/tag/:id', require('./routes/allnow/tag'));
|
||||
router.get('/allnow/user/:id', require('./routes/allnow/user'));
|
||||
router.get('/allnow', require('./routes/allnow/index'));
|
||||
|
||||
// 证券时报网
|
||||
router.get('/stcn/news/:id?', require('./routes/stcn/news'));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const rootUrl = 'https://www.allnow.com';
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: rootUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
const list = $('.post-list .post')
|
||||
.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:"(.*?)"\}/)[1] + ' GMT+8').toUTCString();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '首页 - 全现在',
|
||||
link: rootUrl,
|
||||
item: items,
|
||||
description: $('p.desc').text(),
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const rootUrl = 'https://www.allnow.com';
|
||||
const currentUrl = `${rootUrl}/tag/${ctx.params.id}`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
const list = $('.post-list .post')
|
||||
.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:"(.*?)"\}/)[1] + ' GMT+8').toUTCString();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${$('p.title').eq(0).text()} - 全现在`,
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const rootUrl = 'https://www.allnow.com';
|
||||
const currentUrl = `${rootUrl}/user/${ctx.params.id}`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
const list = $('.post-list .post')
|
||||
.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:"(.*?)"\}/)[1] + ' GMT+8').toUTCString();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${$('p.title').eq(0).text()} - 全现在`,
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue