feat: add 中国政协网 (#6555)

This commit is contained in:
Ethan Shen 2020-12-29 01:09:48 +08:00 committed by GitHub
parent 3fb58e7ea8
commit 6a2a996a56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 0 deletions

View File

@ -280,6 +280,18 @@ pageClass: routes
<Route author="EsuRt" example="/gov/statecouncil/briefing" path="/gov/statecouncil/briefing"/>
## 中国政协网
### 栏目
<Route author="nczitzk" example="/cppcc" path="/cppcc/:slug?" :paramsDesc="['见下文']">
将目标栏目的网址拆解为 `http://www.cppcc.gov.cn/` 和后面的字段,去掉 `.shtml` 后,把后面的字段中的 `/` 替换为 `-`,即为该路由的 slug
如:(委员建言)[http://www.cppcc.gov.cn/zxww/newcppcc/wyjy/index.shtml] 的网址在 `http://www.cppcc.gov.cn/` 后的字段是 `zxww/newcppcc/wyjy/index.shtml`,则对应的 slug 为 `zxww-newcppcc-wyjy-index`,对应的路由即为 `/cppcc/zxww-newcppcc-wyjy-index`
</Route>
### 北京市人民政府
#### 北京教育考试院

View File

@ -3767,6 +3767,9 @@ router.get('/sciencenet/blog/:type?/:time?/:sort?', require('./routes/sciencenet
// DailyArt
router.get('/dailyart/:language?', require('./routes/dailyart/index'));
// 中国政协网
router.get('/cppcc/:slug?', require('./routes/gov/cppcc/index'));
// National Association of Colleges and Employers
router.get('/nace/blog/:sort?', require('./routes/nace/blog'));

View File

@ -0,0 +1,49 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const slug = ctx.params.slug || 'zxww-newcppcc-zxyw-index';
const rootUrl = 'http://www.cppcc.gov.cn';
const currentUrl = `${rootUrl}/${slug.replace(/-/g, '/')}.shtml`;
const response = await got({
method: 'get',
url: currentUrl,
});
const list = response.data
.match(/new title_array\('(.*)','(.*)','\d{4}-\d{2}-\d{2}'\);/g)
.slice(0, 15)
.map((item) => {
const array = item.replace(/new title_array\(|\);|'/g, '').split(',');
return {
link: array[0],
title: array[1],
pubDate: new Date(array[2]).toUTCString(),
};
});
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.description = content('.cnt_box .con').html();
item.author = content('.info em').text().split('')[1];
return item;
})
)
);
ctx.state.data = {
title: `${response.data.match(/<span>><\/span>(.*)<\/p>/)[1]} - 中国政协网`,
link: currentUrl,
item: items,
};
};