From ac6977a16e43047489e5fd01c34607cead0f1239 Mon Sep 17 00:00:00 2001 From: Chenyang Shi Date: Mon, 22 Jul 2019 15:55:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E8=AF=81=E7=9B=91=E4=BC=9A?= =?UTF-8?q?=E6=B6=88=E6=81=AF=20(#2664)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/government.md | 10 ++++++++++ lib/router.js | 2 +- lib/routes/csrc/news.js | 16 +++++++++------- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/docs/government.md b/docs/government.md index 8444dffb20..80be0a766f 100644 --- a/docs/government.md +++ b/docs/government.md @@ -77,6 +77,16 @@ pageClass: routes +## 中国证券监督管理委员会 + +### 发审委公告 + + + +### 证监会消息 + + + ## 中国驻外使领馆 ### 大使馆重要通知 diff --git a/lib/router.js b/lib/router.js index 191b1a1785..23e922a67e 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1470,7 +1470,7 @@ router.get('/8btc/:authorid', require('./routes/8btc/author')); router.get('/vuevideo/:userid', require('./routes/vuevideo/user')); // 证监会 -router.get('/csrc/news', require('./routes/csrc/news')); +router.get('/csrc/news/:suffix?', require('./routes/csrc/news')); router.get('/csrc/fashenwei', require('./routes/csrc/fashenwei')); // LWN.net Alerts diff --git a/lib/routes/csrc/news.js b/lib/routes/csrc/news.js index d91b703350..0ee5e93ada 100644 --- a/lib/routes/csrc/news.js +++ b/lib/routes/csrc/news.js @@ -1,10 +1,14 @@ const cheerio = require('cheerio'); const got = require('@/utils/got'); +const { resolve } = require('url'); module.exports = async (ctx) => { - const url = 'http://www.csrc.gov.cn/pub/newsite/zjhxwfb/xwdd/'; + let suffix = ctx.params.suffix || 'zjhxwfb-xwdd'; + suffix = suffix.replace('-', '/'); + const url = resolve('http://www.csrc.gov.cn/pub/newsite/', suffix + '/'); const res = await got.get(url); const $ = cheerio.load(res.data); + const title = $('div.title .bt').text(); const list = $('.fl_list li').get(); const out = await Promise.all( @@ -12,10 +16,8 @@ module.exports = async (ctx) => { const $ = cheerio.load(item); const time = $('span').text(); const title = $('a').text(); - const sub_url = $('a') - .attr('href') - .slice(2); - const itemUrl = url + sub_url; + const sub_url = $('a').attr('href'); + const itemUrl = resolve(url, sub_url); const cache = await ctx.cache.get(itemUrl); if (cache) { return Promise.resolve(JSON.parse(cache)); @@ -29,14 +31,14 @@ module.exports = async (ctx) => { pubDate: new Date(time).toUTCString(), link: itemUrl, guid: itemUrl, - description: $d('.content .Custom_UnionStyle').html(), + description: $d('.content .Custom_UnionStyle').html() || $d('.contentss').html() || $d('.Section0').html(), }; ctx.cache.set(itemUrl, JSON.stringify(single)); return Promise.resolve(single); }) ); ctx.state.data = { - title: $('title').text(), + title: `中国证券监督管理委员会-${title}`, link: url, item: out, };