feat: add 格隆汇 (#5090)

This commit is contained in:
Ethan Shen
2020-07-02 12:16:25 +08:00
committed by GitHub
parent 16ff4a1c2c
commit f4d824ea0a
5 changed files with 146 additions and 0 deletions
+14
View File
@@ -48,6 +48,20 @@ pageClass: routes
<Route author="Wsine" example="/futunn/highlights" path="/futunn/highlights" />
## 格隆汇
### 用户文章
<Route author="nczitzk" example="/gelonghui/user/5273" path="/gelonghui/user/:id" :paramsDesc="['用户编号, 可在用户页 URL 中找到']"/>
### 主题文章
<Route author="nczitzk" example="/gelonghui/subject/4" path="/gelonghui/subject/:id" :paramsDesc="['主题编号, 可在主题页 URL 中找到']"/>
### 搜索关键字
&lt;Route author="nczitzk" example="/gelonghui/keyword/ 早报" path="/gelonghui/keyword/:keyword" :paramsDesc="[' 搜索关键字']/>
## 淘股吧股票论坛
### 论坛总版
+5
View File
@@ -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'));
+37
View File
@@ -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(),
};
};
+43
View File
@@ -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(),
};
};
+47
View File
@@ -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(),
};
};