diff --git a/docs/new-media.md b/docs/new-media.md index d49d5e6525..b47ee7b05d 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1682,8 +1682,18 @@ column 为 third 时可选的 category: ## 全现在 +### 专栏 + +### 话题 + + + +### 用户 + + + ## 人人都是产品经理 ### 热门文章 diff --git a/lib/router.js b/lib/router.js index 5f20b21fee..d5182b6786 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/allnow/index.js b/lib/routes/allnow/index.js new file mode 100644 index 0000000000..42395be25a --- /dev/null +++ b/lib/routes/allnow/index.js @@ -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(), + }; +}; diff --git a/lib/routes/allnow/tag.js b/lib/routes/allnow/tag.js new file mode 100644 index 0000000000..d5c127b0fe --- /dev/null +++ b/lib/routes/allnow/tag.js @@ -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, + }; +}; diff --git a/lib/routes/allnow/user.js b/lib/routes/allnow/user.js new file mode 100644 index 0000000000..9148e3f4b6 --- /dev/null +++ b/lib/routes/allnow/user.js @@ -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, + }; +};