diff --git a/docs/government.md b/docs/government.md index 38f10a91b0..7ca063f443 100644 --- a/docs/government.md +++ b/docs/government.md @@ -155,6 +155,18 @@ pageClass: routes +### 图解 + + + +| 总理活动图解 | 每周一画 | 其他漫画 | 图解政策 | 其他图解 | +| ------------ | -------- | -------- | -------- | -------- | +| zlhd | mzyh | qtmh | zhengce | qttj | + +全部分类参见 [图解图表](http://www.gov.cn/xinwen/tujie/index.htm) + + + ### 最新政策 diff --git a/lib/router.js b/lib/router.js index abf6020e6d..8032a5278b 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1211,6 +1211,7 @@ router.get('/gov/city/:name/:category', require('./routes/gov/city')); router.get('/gov/statecouncil/briefing', require('./routes/gov/statecouncil/briefing')); router.get('/gov/news/:uid', require('./routes/gov/news')); router.get('/gov/shuju/:caty/:item', require('./routes/gov/shuju')); +router.get('/gov/xinwen/tujie/:caty', require('./routes/gov/xinwen/tujie')); // 苏州 router.get('/gov/suzhou/news/:uid', require('./routes/gov/suzhou/news')); diff --git a/lib/routes/gov/xinwen/tujie.js b/lib/routes/gov/xinwen/tujie.js new file mode 100644 index 0000000000..adf15b6c6f --- /dev/null +++ b/lib/routes/gov/xinwen/tujie.js @@ -0,0 +1,76 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const config = { + zlhd: { + link: '/tujie/zlhd.htm', + title: '总理活动图解', + }, + mzyh: { + link: '/manhua/mzyh.htm', + title: '每周一画', + }, + qtmh: { + link: '/manhua/qita.htm', + title: '其他漫画', + }, + zhengce: { + link: '/tujie/zhengce.htm', + title: '图解政策', + }, + qttj: { + link: '/tujie/qita.htm', + title: '其他图解', + }, +}; + +module.exports = async (ctx) => { + const cfg = config[ctx.params.caty]; + if (!cfg) { + throw Error('Bad category. See docs'); + } + + const rootUrl = 'http://www.gov.cn/xinwen'; + const currentUrl = rootUrl + cfg.link; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + const list = $('div.Video_pane div.tplgd') + .slice(0, 15) + .map((_, item) => { + item = $(item); + const a = item.find('a').eq(1); + return { + title: a.text(), + link: `http://www.gov.cn${a.attr('href')}`, + }; + }) + .get(); + + 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('div.pages_content').html(); + item.pubDate = new Date(content('div.pages-date').text().split('来源:')[0] + ' GMT+8').toUTCString(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${cfg.title} - 中国政府网`, + link: currentUrl, + item: items, + }; +};