From 41c500a6e6e6aa4c8deabfbed63e3e7d3d1625a5 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Tue, 8 Dec 2020 19:23:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E6=97=A0=E4=BA=A7=E8=80=85?= =?UTF-8?q?=E8=AF=84=E8=AE=BA=20(#6376)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/new-media.md | 24 +++++++++++++++++ lib/router.js | 3 +++ lib/routes/proletar/index.js | 52 ++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 lib/routes/proletar/index.js diff --git a/docs/new-media.md b/docs/new-media.md index 77998bea6c..4647a9e061 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1753,6 +1753,30 @@ column 为 third 时可选的 category: +## 无产者评论 + +### 分类 + + + +| 全部文章 | 中流击水 | 革命文艺 | 当代中国 | 理论视野 | 国际观察 | 史海沉钩 | +| -------- | -------- | -------- | -------- | -------- | -------- | -------- | +| | 中流击水 | 革命文艺 | 当代中国 | 理论视野 | 国际观察 | 史海沉钩 | + + + +### 标签 + + + +::: tip 提示 + +标签名参见 [所有标签](https://review.proletar.ink/tags) + +::: + + + ## 西祠胡同 ### 频道 diff --git a/lib/router.js b/lib/router.js index 5249d5f7ae..85df4db4cf 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3661,6 +3661,9 @@ router.get('/tesla', require('./routes/tesla/update')); // 复旦大学继续教育学院 router.get('/fudan/cce', require('./routes/universities/fudan/cce')); +// 无产者评论 +router.get('/proletar/:type?/:id?', require('./routes/proletar/index')); + // QTTabBar router.get('/qttabbar/change-log', require('./routes/qttabbar/change-log')); diff --git a/lib/routes/proletar/index.js b/lib/routes/proletar/index.js new file mode 100644 index 0000000000..ee7166301f --- /dev/null +++ b/lib/routes/proletar/index.js @@ -0,0 +1,52 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const type = ctx.params.type || ''; + const id = ctx.params.id || ''; + + const rootUrl = 'https://review.proletar.ink'; + const currentUrl = `${rootUrl}/${type === '' && id === '' ? 'posts' : `${type}/${id}`}`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.archive-item-link') + .slice(0, 15) + .map((_, item) => { + item = $(item); + return { + title: item.text(), + 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.author = content('.post-author').text(); + item.description = content('#content').html(); + item.pubDate = new Date(detailResponse.data.match(/"datePublished":"(.*)","dateModified"/)[1]).toUTCString(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +};