diff --git a/docs/finance.md b/docs/finance.md index 8daa2c74cc..c6b8cebb3b 100644 --- a/docs/finance.md +++ b/docs/finance.md @@ -48,6 +48,20 @@ pageClass: routes +## 格隆汇 + +### 用户文章 + + + +### 主题文章 + + + +### 搜索关键字 + +<Route author="nczitzk" example="/gelonghui/keyword/ 早报" path="/gelonghui/keyword/:keyword" :paramsDesc="[' 搜索关键字']/> + ## 淘股吧股票论坛 ### 论坛总版 diff --git a/lib/router.js b/lib/router.js index cc504c9d0a..33ad4ceb4a 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2902,6 +2902,11 @@ router.get('/erbingapp/news', require('./routes/erbingapp/news')); // 电商报 router.get('/dsb/area/:area', require('./routes/dsb/area')); +// 格隆汇 +router.get('/gelonghui/user/:id', require('./routes/gelonghui/user')); +router.get('/gelonghui/subject/:id', require('./routes/gelonghui/subject')); +router.get('/gelonghui/keyword/:keyword', require('./routes/gelonghui/keyword')); + // 光谷社区 router.get('/guanggoo/:caty', require('./routes/guanggoo/index')); diff --git a/lib/routes/gelonghui/keyword.js b/lib/routes/gelonghui/keyword.js new file mode 100644 index 0000000000..f0cf4b1abb --- /dev/null +++ b/lib/routes/gelonghui/keyword.js @@ -0,0 +1,37 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const currentUrl = `https://www.gelonghui.com/api/search/post?keyword=${ctx.params.keyword}&count=20&page=1&type=all`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + const $ = cheerio.load(response.data); + + const list = response.data.result.postList.map((item) => ({ + title: item.title, + link: `https://www.gelonghui.com/p/${item.id}`, + pubDate: new Date(item.createDate).toUTCString(), + })); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const res = await got({ method: 'get', url: item.link }); + const content = cheerio.load(res.data); + + item.description = content('article.article-with-html').html(); + return item; + }) + ) + ); + + ctx.state.data = { + title: `格隆汇 - 关键词 “${ctx.params.keyword}” 的文章`, + link: currentUrl, + item: items, + description: $('p.search-number').text(), + }; +}; diff --git a/lib/routes/gelonghui/subject.js b/lib/routes/gelonghui/subject.js new file mode 100644 index 0000000000..faa1ee4bfb --- /dev/null +++ b/lib/routes/gelonghui/subject.js @@ -0,0 +1,43 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const currentUrl = `https://www.gelonghui.com/subject/${ctx.params.id}`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + const $ = cheerio.load(response.data); + const list = $('#subject-article ul li') + .slice(0, 15) + .map((_, item) => { + item = $(item); + const h = item.find('h2').length === 0 ? item.find('p') : item.find('h2'); + return { + title: h.text(), + link: h.parent().attr('href'), + pubDate: new Date(item.find('span').eq(2).text()).toUTCString(), + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const res = await got({ method: 'get', url: item.link }); + const content = cheerio.load(res.data); + + item.description = content('article.article-with-html').html(); + return item; + }) + ) + ); + + ctx.state.data = { + title: `格隆汇 - 主题 ${$('span.user-nick').text()} 的文章`, + link: currentUrl, + item: items, + description: $('div.user-name').parent().children('p').text(), + }; +}; diff --git a/lib/routes/gelonghui/user.js b/lib/routes/gelonghui/user.js new file mode 100644 index 0000000000..9a276dedd2 --- /dev/null +++ b/lib/routes/gelonghui/user.js @@ -0,0 +1,47 @@ +const url = require('url'); +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const currentUrl = `https://www.gelonghui.com/user/${ctx.params.id}`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + const $ = cheerio.load(response.data); + const list = $('section.item') + .slice(0, 15) + .map((_, item) => { + item = $(item); + const h = item.find('h2'); + const pubDate = item.find('p').text(); + return { + title: h.text(), + link: url.resolve(`https://www.gelonghui.com`, h.parent().attr('href')), + pubDate: new Date( + pubDate.substr(pubDate.length - 1, 1) !== '分' ? new Date().getFullYear() + '-' + pubDate : pubDate.replace('年', '-').replace('月', '-').replace('日', ' ').replace('时', ':').replace('分', '') + ).toUTCString(), + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const res = await got({ method: 'get', url: item.link }); + const content = cheerio.load(res.data); + + item.description = content('article.article-with-html').html(); + return item; + }) + ) + ); + + ctx.state.data = { + title: `格隆汇 - 用户 ${$('p.nick').text()} 的文章`, + link: currentUrl, + item: items, + description: $('div.val').text(), + }; +};