diff --git a/docs/government.md b/docs/government.md index 059809a44..4f5276acd 100644 --- a/docs/government.md +++ b/docs/government.md @@ -280,6 +280,18 @@ pageClass: routes +## 中国政协网 + +### 栏目 + + + +将目标栏目的网址拆解为 `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` + + + ### 北京市人民政府 #### 北京教育考试院 diff --git a/lib/router.js b/lib/router.js index 771d6d286..1612e4b4b 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/gov/cppcc/index.js b/lib/routes/gov/cppcc/index.js new file mode 100644 index 000000000..e0d71a856 --- /dev/null +++ b/lib/routes/gov/cppcc/index.js @@ -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>(.*)<\/p>/)[1]} - 中国政协网`, + link: currentUrl, + item: items, + }; +};