feat(route): add 人民论坛网思想理论 (#7872)

Co-authored-by: NeverBehave <gayhub@never.pet>
This commit is contained in:
Ethan Shen
2021-07-17 02:14:52 -07:00
committed by GitHub
co-authored by NeverBehave
parent de03bc750d
commit 96331588d5
3 changed files with 78 additions and 0 deletions
+20
View File
@@ -1822,6 +1822,26 @@ column 为 third 时可选的 category:
<Route author="nczitzk" example="/allnow/user/1891141" path="/allnow/user/:id" :paramsDesc="['用户 id']"/>
## 人民论坛网
### 思想理论
<Route author="nczitzk" example="/rmlt/idea" path="/rmlt/idea/:category?" :paramsDesc="['分类,见下表,默认为首页']">
| 首页 | 独家连线 | 深度原创 | 中外思潮 | 时事洞察 |
| ---- | ---------- | ---------- | -------- | -------- |
| | connection | yuanchuang | sichao | dongcha |
| 中国声音 | 全球观察 | 思想名人堂 | 学术人生 |
| -------- | -------- | ----------- | -------- |
| shengyin | guancha | mingrentang | xueshu |
| 前沿理论 | 比较研究 |
| -------- | -------- |
| lilun | yanjiu |
</Route>
## 人人都是产品经理
### 热门文章
+3
View File
@@ -4131,6 +4131,9 @@ router.get('/caus/:category?', require('./routes/caus'));
// 摩点
router.get('/modian/zhongchou/:category?/:sort?/:status?', require('./routes/modian/zhongchou'));
// 人民论坛网
router.get('/rmlt/idea/:category?', require('./routes/rmlt/idea'));
// CBNData
router.get('/cbndata/information/:category?', require('./routes/cbndata/information'));
+55
View File
@@ -0,0 +1,55 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const category = ctx.params.category || '';
const rootUrl = 'http://www.rmlt.com.cn';
const currentUrl = `${rootUrl}/idea/${category}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $(category ? '.txt-list' : '.hot-news')
.find('a')
.slice(0, 15)
.map((_, item) => {
item = $(item);
return {
link: 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('.article-title').text();
item.description = content('.article-content').html();
item.pubDate = timezone(parseDate(content('.date').text(), 'YYYY-MM-DD HH:ss'), +8);
return item;
})
)
);
ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
};
};