diff --git a/docs/government.md b/docs/government.md index aaa1ed5d9..7db2781c2 100644 --- a/docs/government.md +++ b/docs/government.md @@ -188,6 +188,12 @@ pageClass: routes | 贝尔法斯特 | `/embassy/uk/belfast` | | 曼彻斯特 | `/embassy/uk/manchester` | +## 中华人民共和国商务部 + +### 政务公开 + + + ## 中华人民共和国生态环境部 ### 公示 diff --git a/lib/router.js b/lib/router.js index 747938b3f..9c6e2919a 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1591,4 +1591,7 @@ router.get('/aliyun/database_month', require('./routes/aliyun/database_month')); // 礼物说 router.get('/liwushuo/index', require('./routes/liwushuo/index.js')); +// 中华人民共和国商务部 +router.get('/mofcom/article/:suffix', require('./routes/mofcom/article')); + module.exports = router; diff --git a/lib/routes/mofcom/article.js b/lib/routes/mofcom/article.js new file mode 100644 index 000000000..6527b2287 --- /dev/null +++ b/lib/routes/mofcom/article.js @@ -0,0 +1,43 @@ +const cheerio = require('cheerio'); +const got = require('@/utils/got'); +const { resolve } = require('url'); + +const host = 'http://www.mofcom.gov.cn'; + +module.exports = async (ctx) => { + const suffix = ctx.params.suffix; + const url = resolve('http://www.mofcom.gov.cn/article/', suffix); + const res = await got.get(url); + const $ = cheerio.load(res.data); + const title = $('head > title').text(); + const list = $('.u-newsList01.f-mt10 li').get(); + + const out = await Promise.all( + list.map(async (item) => { + const $ = cheerio.load(item); + const title = $('a').attr('title'); + const sub_url = $('a').attr('href'); + const itemUrl = resolve(host, sub_url); + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const responses = await got.get(itemUrl); + const $d = cheerio.load(responses.data); + + const single = { + title, + link: itemUrl, + description: $d('.artCon').html(), + }; + ctx.cache.set(itemUrl, JSON.stringify(single)); + return Promise.resolve(single); + }) + ); + ctx.state.data = { + title: title, + link: url, + item: out, + }; +};