feat(router): ccac 澳门廉政公署 (#8273)
Co-authored-by: Tony <TonyRL@users.noreply.github.com>
This commit is contained in:
parent
daf95a4709
commit
0edd6a7387
|
|
@ -20,7 +20,20 @@ pageClass: routes
|
|||
|
||||
### 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)']">
|
||||
<RouteEn 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)']"/>
|
||||
|
||||
## Macau Independent Commission Against Corruption
|
||||
|
||||
### Latest News
|
||||
|
||||
<RouteEn author="linbuxiao" example="/ccac/news/all" path="/ccac/news/:type/:lang?" :paramsDesc="['Category', 'Language, default to `sc`. Supprot `en`(English), `sc`(Simplified Chinese), `tc`(Traditional Chinese) and `pt`(Portuguese)']">
|
||||
Category
|
||||
|
||||
| All | Detected Cases | Investigation Reports or Recommendations | Annual Reports | CCAC's Updates |
|
||||
| ---- | -------------- | ----------------------------------------- | -------------- | -------------- |
|
||||
| all | case | Persuasion | AnnualReport | PCANews |
|
||||
|
||||
</RouteEn>
|
||||
|
||||
## Ministry of Foreign Affairs of Japan
|
||||
|
||||
|
|
|
|||
|
|
@ -250,7 +250,19 @@ pageClass: routes
|
|||
|
||||
### 新闻公布
|
||||
|
||||
<Route author="linbuxiao" example="/icac/news/sc" path="/icac/news/:lang?" :paramsDesc="['语言,留空为`sc`,支持`sc`(简中),`tc`(繁中),`en`(英文)']">
|
||||
<Route author="linbuxiao" example="/icac/news/sc" path="/icac/news/:lang?" :paramsDesc="['语言,留空为`sc`,支持`sc`(简中),`tc`(繁中),`en`(英文)']"/>
|
||||
|
||||
## 澳门廉政公署
|
||||
|
||||
### 最新消息
|
||||
|
||||
<Route author="linbuxiao" example="/ccac/news/all" path="/ccac/news/:type/:lang?" :paramsDesc="['类别', '语言,留空为`sc`,支持`sc`(简中),`tc`(繁中),`en`(英文),`pt`(葡萄牙文)']">
|
||||
|
||||
| 全部 | 案件发布 | 调查报告或勘喻 | 年度报告 | 公署消息 |
|
||||
| ---- | ------- | ------------ | ------------- | --------- |
|
||||
| all | case | Persuasion | AnnualReport | PCANews |
|
||||
|
||||
</Route>
|
||||
|
||||
## 中国工业和信息化部
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/news/:type/:lang?': ['linbuxiao'],
|
||||
};
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
const utils = require('./utils');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const browser = await require('@/utils/puppeteer')();
|
||||
const lang = ctx.params.lang ?? 'sc';
|
||||
const type = utils.TYPE[ctx.params.type];
|
||||
|
||||
const BASE = utils.langBase(lang);
|
||||
const page = await browser.newPage();
|
||||
await page.goto(BASE);
|
||||
const articles = await page.evaluate(() => window.articles);
|
||||
|
||||
const list = utils
|
||||
.typeFilter(articles, type)
|
||||
.slice(0, 11)
|
||||
.map((item) => ({
|
||||
title: item.name,
|
||||
category: item.tags.map((tag) => tag.name).join(','),
|
||||
link: utils.BASE_URL + item.url,
|
||||
pubDate: parseDate(item.time, 'YYYY-MM-DD'),
|
||||
}));
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(detailResponse.data);
|
||||
$('.article_details_body > *').removeAttr('style');
|
||||
item.description = $('.article_details_body').html();
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
ctx.state.data = {
|
||||
title: `CCAC ${type}`,
|
||||
link: BASE,
|
||||
description: `CCAC ${type}`,
|
||||
language: ctx.params.lang ? utils.LANG_TYPE[ctx.params.lang] : utils.LANG_TYPE.sc,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
module.exports = {
|
||||
'ccac.org.mo': {
|
||||
_name: '澳门廉政公署',
|
||||
'.': [
|
||||
{
|
||||
title: '最新消息',
|
||||
docs: 'https://docs.rsshub.app/government.html#ao-men-lian-zheng-gong-shu',
|
||||
source: ['/:lang/news.html'],
|
||||
target: '/ccac/news/all/:lang',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/news/:type/:lang?', require('./news'));
|
||||
};
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
const BASE_URL = 'https://www.ccac.org.mo';
|
||||
|
||||
const LANG_TYPE = {
|
||||
en: 'en-us',
|
||||
sc: 'zh-cn',
|
||||
tc: 'zh-hk',
|
||||
pt: 'pt',
|
||||
};
|
||||
|
||||
const TYPE = {
|
||||
all: '全部',
|
||||
case: '案件發佈',
|
||||
Persuasion: '調查報告或勸喻',
|
||||
AnnualReport: '年度報告',
|
||||
PCANews: '公署消息',
|
||||
};
|
||||
|
||||
function langBase(lang) {
|
||||
return `${BASE_URL}/${lang}/news.html`;
|
||||
}
|
||||
|
||||
function typeFilter(list, type) {
|
||||
return type === '全部' ? list : list.filter((item) => item.tags.some((tag) => tag.name === type));
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
TYPE,
|
||||
BASE_URL,
|
||||
LANG_TYPE,
|
||||
langBase,
|
||||
typeFilter,
|
||||
};
|
||||
|
|
@ -11,8 +11,8 @@ module.exports = async (ctx) => {
|
|||
const list = $('.pressItem.clearfix')
|
||||
.map((_, e) => {
|
||||
const c = cheerio.load(e);
|
||||
|
||||
return {
|
||||
title: c('.hd a').text(),
|
||||
link: `${utils.BASE_URL}${c('.hd a').attr('href')}`,
|
||||
};
|
||||
})
|
||||
|
|
@ -30,7 +30,6 @@ module.exports = async (ctx) => {
|
|||
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;
|
||||
|
|
@ -39,7 +38,7 @@ module.exports = async (ctx) => {
|
|||
);
|
||||
ctx.state.data = {
|
||||
title: 'ICAC 新闻公布',
|
||||
link: 'https://www.icac.org.hk/tc/press/index.html',
|
||||
link: `${BASE_WITH_LANG}/press/index.html`,
|
||||
description: 'ICAC 新闻公布',
|
||||
language: ctx.params.lang ? utils.LANG_TYPE[ctx.params.lang] : utils.LANG_TYPE.sc,
|
||||
item: items,
|
||||
|
|
|
|||
Loading…
Reference in New Issue