diff --git a/docs/government.md b/docs/government.md index 5ce306318a..747ccec8dd 100644 --- a/docs/government.md +++ b/docs/government.md @@ -16,6 +16,18 @@ pageClass: routes +## 广东省人民政府 + +### 广东省教育厅 + + + +| 通知公告 | 本厅信息 | 新闻发布 | 媒体聚焦 | 广东教育 | 教育动态 | 图片新闻 | 政声传递 | +| :------: | :------: | :------: | :------: | :------: | :------: | :------: | :------: | +| tzgg | btxx | xwfb | mtjj | gdjy | jydt | tpxw | zscd | + + + ## 国家新闻出版广电总局 ### 游戏审批结果 diff --git a/lib/router.js b/lib/router.js index c53a74e2c4..5247277f7c 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1200,6 +1200,9 @@ router.get('/gov/beijing/mhc/:caty', require('./routes/gov/beijing/mhc')); // 北京考试院 router.get('/gov/beijing/bjeea/:type', require('./routes/gov/beijing/eea')); +// 广东省教育厅 +router.get('/gov/guangdong/edu/:caty', require('./routes/gov/guangdong/edu')); + // 小黑盒 router.get('/xiaoheihe/user/:id', require('./routes/xiaoheihe/user')); router.get('/xiaoheihe/news', require('./routes/xiaoheihe/news')); diff --git a/lib/routes/gov/guangdong/edu.js b/lib/routes/gov/guangdong/edu.js new file mode 100644 index 0000000000..de35d1badd --- /dev/null +++ b/lib/routes/gov/guangdong/edu.js @@ -0,0 +1,80 @@ +const url = require('url'); +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const rootUrl = 'http://edu.gd.gov.cn/'; + +const config = { + tzgg: { + link: '/zxzx/tzgg/', + title: '通知公告', + }, + btxx: { + link: '/zxzx/btxx/', + title: '本厅信息', + }, + xwfb: { + link: '/zxzx/xwfb/', + title: '新闻发布', + }, + mtjj: { + link: '/zxzx/mtjj/', + title: '媒体聚焦', + }, + gdjy: { + link: '/zxzx/gdjy/', + title: '广东教育', + }, + jydt: { + link: '/zxzx/jydt/', + title: '教育动态', + }, + tpxw: { + link: '/zxzx/tpxw/', + title: '图片新闻', + }, + zscd: { + link: '/zxzx/tzgg/', + title: '政声传递', + }, +}; + +module.exports = async (ctx) => { + const cfg = config[ctx.params.caty]; + if (!cfg) { + throw Error('Bad category. See docs'); + } + + const currentUrl = url.resolve(rootUrl, cfg.link); + const response = await got({ method: 'get', url: currentUrl }); + + const $ = cheerio.load(response.data); + const list = $('div.list_list ul li') + .map((_, item) => { + item = $(item).find('a'); + return { + title: item.text(), + link: item.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.concent_center').html(); + item.pubDate = new Date(content('td[align="right"]').text().replace(/发布日期:/, '') + ' GMT+8').toUTCString(); + return item; + }) + ) + ); + + ctx.state.data = { + title: '广东省教育厅 - ' + cfg.title, + link: currentUrl, + item: items, + }; +};