From 213b1140f03c75336f9f0fdf9d3150209db97863 Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Wed, 15 Jun 2022 15:14:53 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E8=85=BE=E8=AE=AF?= =?UTF-8?q?=E4=BA=91=E4=BA=91+=E7=A4=BE=E5=8C=BA=E4=B8=93=E6=A0=8F=20(#995?= =?UTF-8?q?2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/programming.md | 6 ++++ lib/v2/tencent/cloud/column.js | 51 ++++++++++++++++++++++++++++++++++ lib/v2/tencent/maintainer.js | 1 + lib/v2/tencent/radar.js | 11 ++++++++ lib/v2/tencent/router.js | 1 + 5 files changed, 70 insertions(+) create mode 100644 lib/v2/tencent/cloud/column.js diff --git a/docs/programming.md b/docs/programming.md index ce064a9e7..2c31a28ab 100644 --- a/docs/programming.md +++ b/docs/programming.md @@ -1045,6 +1045,12 @@ GitHub 官方也提供了一些 RSS: +## 腾讯云 + +### 云 + 社区专栏 + + + ## 微信开放平台 ### 微信开放社区 - 小程序公告 diff --git a/lib/v2/tencent/cloud/column.js b/lib/v2/tencent/cloud/column.js new file mode 100644 index 000000000..60aca82c4 --- /dev/null +++ b/lib/v2/tencent/cloud/column.js @@ -0,0 +1,51 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const id = ctx.params.id ?? '86410'; + const tag = ctx.params.tag ?? ''; + + const rootUrl = 'https://cloud.tencent.com'; + const currentUrl = `${rootUrl}/developer/column/${id}${tag ? `/tag-${tag}` : ''}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const data = JSON.parse(response.data.match(/window\.\$render\((.*?)\);/)[1]); + + let items = data.articleData.list.map((item) => ({ + title: item.title, + author: item.author.name, + link: `${rootUrl}/developer/article/${item.id}`, + pubDate: parseDate(item.updateTime * 1000), + category: item.tags.map((tag) => tag.name), + })); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + content('.developer-code-block').remove(); + + item.description = content('.rno-markdown').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${data.columnDetail.name} - ${data.documentBaseTitle}`, + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/tencent/maintainer.js b/lib/v2/tencent/maintainer.js index 336c84ad8..c8eaa0ce0 100644 --- a/lib/v2/tencent/maintainer.js +++ b/lib/v2/tencent/maintainer.js @@ -1,3 +1,4 @@ module.exports = { '/qq/sdk/changelog/:platform': ['nuomi1'], + '/cloud/column/:id?/:tag?': ['nczitzk'], }; diff --git a/lib/v2/tencent/radar.js b/lib/v2/tencent/radar.js index dde59d629..afbe48b6a 100644 --- a/lib/v2/tencent/radar.js +++ b/lib/v2/tencent/radar.js @@ -53,4 +53,15 @@ module.exports = { }, ], }, + 'tencent.com': { + _name: '腾讯云', + '.': [ + { + title: '云+社区专栏', + docs: 'https://docs.rsshub.app/programming.html#teng-xun-yun-yun-she-qu-zhuan-lan', + source: ['/developer/column/:id', '/developer/column/:id/:tag', '/'], + target: (params, url) => `/tencent/cloud/column/${url.match(/column\/(\d+)/)[1]}${/\/tag-\d+/.test(url) ? `/${url.match(/\/tag-(\d+)/)[1]}` : ''}`, + }, + ], + }, }; diff --git a/lib/v2/tencent/router.js b/lib/v2/tencent/router.js index a708c751e..46f91af6f 100644 --- a/lib/v2/tencent/router.js +++ b/lib/v2/tencent/router.js @@ -1,3 +1,4 @@ module.exports = (router) => { router.get('/qq/sdk/changelog/:platform', require('./qq/sdk/changelog')); + router.get('/cloud/column/:id?/:tag?', require('./cloud/column')); };