feat: icac (#8249)

This commit is contained in:
linbuxiao
2021-09-26 15:08:33 +08:00
committed by GitHub
parent 3441822d74
commit c752ec1dd6
7 changed files with 95 additions and 0 deletions

View File

@@ -67,3 +67,9 @@ Category
### Dispute settlement news
<RouteEn author="nczitzk" example="/wto/dispute-settlement" path="/wto/dispute-settlement/:year?" :paramsDesc="['Year, current year by default']"/>
## Hong Kong Independent Commission Against Corruption
### Press Releases
<Route author="linbuxiao" example="/icac/news/sc" path="/icac/news/:lang?" :paramsDesc="['Language, default to `sc`. Supprot `en`(English), `sc`(Simplified Chinese) and `tc`(Traditional Chinese)']">

View File

@@ -707,3 +707,9 @@ pageClass: routes
### 审查调查
<Route author="LogicJake" example="/ccdi/scdc" path="/ccdi/scdc"/>
## 香港廉政公署
### 新闻公布
<Route author="linbuxiao" example="/icac/news/sc" path="/icac/news/:lang?" :paramsDesc="['语言,留空为`sc`,支持`sc`(简中),`tc`(繁中),`en`(英文)']">

View File

@@ -0,0 +1,3 @@
module.exports = {
'/news/:lang?': ['linbuxiao, TonyRL'],
};

47
lib/v2/icac/news.js Normal file
View File

@@ -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,
};
};

13
lib/v2/icac/radar.js Normal file
View File

@@ -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',
},
],
},
};

3
lib/v2/icac/router.js Normal file
View File

@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/news/:lang?', require('./news'));
};

17
lib/v2/icac/utils.js Normal file
View File

@@ -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,
};