From 96331588d5b98efa073f85f58a91986f86fc5d45 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sat, 17 Jul 2021 17:14:52 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E4=BA=BA=E6=B0=91?= =?UTF-8?q?=E8=AE=BA=E5=9D=9B=E7=BD=91=E6=80=9D=E6=83=B3=E7=90=86=E8=AE=BA?= =?UTF-8?q?=20(#7872)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: NeverBehave --- docs/new-media.md | 20 +++++++++++++++ lib/router.js | 3 +++ lib/routes/rmlt/idea.js | 55 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 lib/routes/rmlt/idea.js diff --git a/docs/new-media.md b/docs/new-media.md index b7e34b040b..17b6aafbd5 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1822,6 +1822,26 @@ column 为 third 时可选的 category: +## 人民论坛网 + +### 思想理论 + + + +| 首页 | 独家连线 | 深度原创 | 中外思潮 | 时事洞察 | +| ---- | ---------- | ---------- | -------- | -------- | +| | connection | yuanchuang | sichao | dongcha | + +| 中国声音 | 全球观察 | 思想名人堂 | 学术人生 | +| -------- | -------- | ----------- | -------- | +| shengyin | guancha | mingrentang | xueshu | + +| 前沿理论 | 比较研究 | +| -------- | -------- | +| lilun | yanjiu | + + + ## 人人都是产品经理 ### 热门文章 diff --git a/lib/router.js b/lib/router.js index 1844db4ab8..3dab40ec6e 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/rmlt/idea.js b/lib/routes/rmlt/idea.js new file mode 100644 index 0000000000..b8747bdac4 --- /dev/null +++ b/lib/routes/rmlt/idea.js @@ -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, + }; +};