From fdf137b53b7dfdff586fcb0661df1a6f1bef1ae4 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Mon, 7 Feb 2022 21:24:41 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=85=A8=E5=9B=BD?= =?UTF-8?q?=E6=B8=AF=E6=BE=B3=E7=A0=94=E7=A9=B6=E4=BC=9A=20(#9011)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/new-media.md | 16 ++++++ lib/v2/cahkms/index.js | 69 +++++++++++++++++++++++++ lib/v2/cahkms/maintainer.js | 3 ++ lib/v2/cahkms/radar.js | 13 +++++ lib/v2/cahkms/router.js | 3 ++ lib/v2/cahkms/templates/description.art | 15 ++++++ 6 files changed, 119 insertions(+) create mode 100644 lib/v2/cahkms/index.js create mode 100644 lib/v2/cahkms/maintainer.js create mode 100644 lib/v2/cahkms/radar.js create mode 100644 lib/v2/cahkms/router.js create mode 100644 lib/v2/cahkms/templates/description.art diff --git a/docs/new-media.md b/docs/new-media.md index 133d77a32..bbdbe9d1c 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -2551,6 +2551,22 @@ column 为 third 时可选的 category: +## 全国港澳研究会 + +### 分类 + + + +| 关于我们 | 港澳新闻 | 重要新闻 | 顾问点评、会员观点 | 专题汇总 | +| -------- | -------- | -------- | ------------------ | -------- | +| 01 | 02 | 03 | 04 | 05 | + +| 港澳时评 | 图片新闻 | 视频中心 | 港澳研究 | 最新书讯 | 研究资讯 | +| -------- | -------- | -------- | -------- | -------- | -------- | +| 06 | 07 | 08 | 09 | 10 | 11 | + + + ## 全民健康网 diff --git a/lib/v2/cahkms/index.js b/lib/v2/cahkms/index.js new file mode 100644 index 000000000..6f3474876 --- /dev/null +++ b/lib/v2/cahkms/index.js @@ -0,0 +1,69 @@ +const got = require('@/utils/got'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); + +const titles = { + '01': '关于我们', + '02': '港澳新闻', + '03': '重要新闻', + '04': '顾问点评、会员观点', + '05': '专题汇总', + '06': '港澳时评', + '07': '图片新闻', + '08': '视频中心', + '09': '港澳研究', + 10: '最新书讯', + 11: '研究资讯', +}; + +module.exports = async (ctx) => { + const category = ctx.params.category ?? '03'; + + const rootUrl = 'http://www.cahkms.org'; + const currentUrl = `${rootUrl}/HKMAC/indexMac/getRightList?dm=${category}&page=1&countPage=${ctx.query.limit ?? 10}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + let items = response.data + .filter((item) => item.ID) + .map((item) => ({ + title: item.TITLE, + description: `

${item.GJZ}

`, + pubDate: timezone(parseDate(item.JDRQ), +8), + link: `${rootUrl}/HKMAC/indexMac/getWzxx?id=${item.ID}`, + })); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + item.author = detailResponse.data.WZLY; + item.description = art(path.join(__dirname, 'templates/description.art'), { + rootUrl, + content: detailResponse.data.CONTENT, + image: detailResponse.data.URL, + files: detailResponse.data.fjlist, + video: detailResponse.data.VIDEO.indexOf('.mp4') > 0 ? detailResponse.data.VIDEO : null, + }); + item.link = `${rootUrl}/HKMAC/webView/mc/AboutUs_1.html?${category}&${titles[category]}`; + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${titles[category]} - 全国港澳研究会`, + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/cahkms/maintainer.js b/lib/v2/cahkms/maintainer.js new file mode 100644 index 000000000..81eb78d73 --- /dev/null +++ b/lib/v2/cahkms/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:category?': ['nczitzk'], +}; diff --git a/lib/v2/cahkms/radar.js b/lib/v2/cahkms/radar.js new file mode 100644 index 000000000..8d0d3197a --- /dev/null +++ b/lib/v2/cahkms/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'cahkms.org': { + _name: '全国港澳研究会', + '.': [ + { + title: '分类', + docs: 'https://docs.rsshub.app/new-media.html#quan-guo-gang-ao-yan-jiu-hui-fen-lei', + source: '/', + target: '/cahkms/:category?', + }, + ], + }, +}; diff --git a/lib/v2/cahkms/router.js b/lib/v2/cahkms/router.js new file mode 100644 index 000000000..cf781366f --- /dev/null +++ b/lib/v2/cahkms/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:category?', require('./index')); +}; diff --git a/lib/v2/cahkms/templates/description.art b/lib/v2/cahkms/templates/description.art new file mode 100644 index 000000000..6382ac79e --- /dev/null +++ b/lib/v2/cahkms/templates/description.art @@ -0,0 +1,15 @@ +{{ if image }} + +{{ /if }} +{{ if content }} +{{@ content }} +{{ /if }} +{{ if video }} + +{{ /if }} +{{ if files }} +
下载附件:
+{{ each files file }} +{{ file.FJMC }}
+{{ /each }} +{{ /if }} \ No newline at end of file