-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Tony <[email protected]>
- Loading branch information
Showing
8 changed files
with
127 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
'/news/:type/:lang?': ['linbuxiao'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = function (router) { | ||
router.get('/news/:type/:lang?', require('./news')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters