From c752ec1dd610e17da844604f99017d02d1477a7a Mon Sep 17 00:00:00 2001
From: linbuxiao <56839018+linbuxiao@users.noreply.github.com>
Date: Sun, 26 Sep 2021 15:08:33 +0800
Subject: [PATCH] feat: icac (#8249)
---
docs/en/government.md | 6 +++++
docs/government.md | 6 +++++
lib/v2/icac/maintainer.js | 3 +++
lib/v2/icac/news.js | 47 +++++++++++++++++++++++++++++++++++++++
lib/v2/icac/radar.js | 13 +++++++++++
lib/v2/icac/router.js | 3 +++
lib/v2/icac/utils.js | 17 ++++++++++++++
7 files changed, 95 insertions(+)
create mode 100644 lib/v2/icac/maintainer.js
create mode 100644 lib/v2/icac/news.js
create mode 100644 lib/v2/icac/radar.js
create mode 100644 lib/v2/icac/router.js
create mode 100644 lib/v2/icac/utils.js
diff --git a/docs/en/government.md b/docs/en/government.md
index c1b1a70dad..4bdc14ae20 100644
--- a/docs/en/government.md
+++ b/docs/en/government.md
@@ -67,3 +67,9 @@ Category
### Dispute settlement news
+
+## Hong Kong Independent Commission Against Corruption
+
+### Press Releases
+
+
diff --git a/docs/government.md b/docs/government.md
index 2e273d59f0..1caeff1b48 100644
--- a/docs/government.md
+++ b/docs/government.md
@@ -707,3 +707,9 @@ pageClass: routes
### 审查调查
+
+## 香港廉政公署
+
+### 新闻公布
+
+
diff --git a/lib/v2/icac/maintainer.js b/lib/v2/icac/maintainer.js
new file mode 100644
index 0000000000..e34474994a
--- /dev/null
+++ b/lib/v2/icac/maintainer.js
@@ -0,0 +1,3 @@
+module.exports = {
+ '/news/:lang?': ['linbuxiao, TonyRL'],
+};
diff --git a/lib/v2/icac/news.js b/lib/v2/icac/news.js
new file mode 100644
index 0000000000..4fde059ae9
--- /dev/null
+++ b/lib/v2/icac/news.js
@@ -0,0 +1,47 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+const utils = require('./utils');
+const { parseDate } = require('@/utils/parse-date');
+
+module.exports = async (ctx) => {
+ const BASE_WITH_LANG = utils.langBase(ctx.params.lang);
+ const res = await got.get(`${BASE_WITH_LANG}/press/index.html`);
+ const $ = cheerio.load(res.data);
+
+ const list = $('.pressItem.clearfix')
+ .map((_, e) => {
+ const c = cheerio.load(e);
+
+ return {
+ link: `${utils.BASE_URL}${c('.hd a').attr('href')}`,
+ };
+ })
+ .get();
+ const items = await Promise.all(
+ list.map((item) =>
+ ctx.cache.tryGet(item.link, async () => {
+ const detailResponse = await got({
+ method: 'get',
+ url: item.link,
+ });
+
+ const c = cheerio.load(detailResponse.data);
+ c('.btn_download').remove();
+ c('.col-3-wrap.clearfix.pressPhoto div').removeAttr('class');
+ const des = c('.pressContent.full').html();
+ const thumbs = c('.col-3-wrap.clearfix.pressPhoto').html() ?? '';
+ item.title = c('h2').text().trim();
+ item.pubDate = parseDate(decodeURI(c('.date').text().trim()), ['YYYY年MM月DD日', 'YYYY年MM月D日', 'YYYY年M月DD日', 'YYYY年M月D日'], true);
+ item.description = des + thumbs;
+ return item;
+ })
+ )
+ );
+ ctx.state.data = {
+ title: 'ICAC 新闻公布',
+ link: 'https://www.icac.org.hk/tc/press/index.html',
+ description: 'ICAC 新闻公布',
+ language: ctx.params.lang ? utils.LANG_TYPE[ctx.params.lang] : utils.LANG_TYPE.sc,
+ item: items,
+ };
+};
diff --git a/lib/v2/icac/radar.js b/lib/v2/icac/radar.js
new file mode 100644
index 0000000000..c1e0dd69d9
--- /dev/null
+++ b/lib/v2/icac/radar.js
@@ -0,0 +1,13 @@
+module.exports = {
+ 'https://www.icac.org.hk': {
+ _name: '廉政公署',
+ '.': [
+ {
+ title: '新闻公布',
+ docs: 'https://docs.rsshub.app/government.html#xiang-gang-lian-zheng-gong-shu',
+ source: ['/:lang/press/index.html'],
+ target: '/icac/news/:lang',
+ },
+ ],
+ },
+};
diff --git a/lib/v2/icac/router.js b/lib/v2/icac/router.js
new file mode 100644
index 0000000000..84ffb5b537
--- /dev/null
+++ b/lib/v2/icac/router.js
@@ -0,0 +1,3 @@
+module.exports = function (router) {
+ router.get('/news/:lang?', require('./news'));
+};
diff --git a/lib/v2/icac/utils.js b/lib/v2/icac/utils.js
new file mode 100644
index 0000000000..1168d21725
--- /dev/null
+++ b/lib/v2/icac/utils.js
@@ -0,0 +1,17 @@
+const BASE_URL = 'https://www.icac.org.hk';
+
+const LANG_TYPE = {
+ en: 'en-us',
+ sc: 'zh-cn',
+ tc: 'zh-hk',
+};
+
+function langBase(lang) {
+ return lang ? `${BASE_URL}/${lang}` : `https://www.icac.org.hk/sc`;
+}
+
+module.exports = {
+ LANG_TYPE,
+ BASE_URL,
+ langBase,
+};