diff --git a/docs/government.md b/docs/government.md index 7787edca2..eb76ada01 100644 --- a/docs/government.md +++ b/docs/government.md @@ -185,6 +185,18 @@ pageClass: routes +## 中国农工民主党 + +### 新闻中心 + + + +将目标栏目的网址拆解为 `http://www.ngd.org.cn/` 和后面的字段,去掉 `.htm` 后,把后面的字段中的 `/` 替换为 `-`,即为该路由的 slug + +如:(要闻动态)[http://www.ngd.org.cn/xwzx/ywdt/index.htm] 的网址在 `http://www.ngd.org.cn/` 后的字段是 `xwzx/ywdt/index.htm`,则对应的 slug 为 `xwzx-ywdt-index`,对应的路由即为 `/ngd/xwzx-ywdt-index` + + + ## 中国人大网 diff --git a/lib/router.js b/lib/router.js index 00588b284..11f9d6f1b 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3785,6 +3785,9 @@ router.get('/nace/blog/:sort?', require('./routes/nace/blog')); // Caixin Latest router.get('/caixin/latest', require('./routes/caixin/latest')); +// 中国农工民主党 +router.get('/ngd/:slug?', require('./routes/gov/ngd/index')); + // SimpRead-消息通知 router.get('/simpread/notice', require('./routes/simpread/notice')); // SimpRead-更新日志 diff --git a/lib/routes/gov/ngd/index.js b/lib/routes/gov/ngd/index.js new file mode 100644 index 000000000..5dfd996fe --- /dev/null +++ b/lib/routes/gov/ngd/index.js @@ -0,0 +1,52 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const slug = ctx.params.slug || 'xwzx-ywdt-index'; + + const rootUrl = 'http://www.ngd.org.cn'; + const currentUrl = `${rootUrl}/${slug.replace(/-/g, '/')}.htm`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.gp-ellipsis a') + .slice(0, 15) + .map((_, item) => { + item = $(item); + return { + title: item.text(), + link: `${currentUrl.replace('/index.htm', '')}/${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); + const info = content('.articleAuthor').text().split('|'); + + item.author = info[0].replace('来源:', ''); + item.description = content('.gp-article').html(); + item.pubDate = new Date(info[info.length - 1].replace('发布时间:', '')).toUTCString(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +};