From 186c78e7cd36c2ceef52bded6e9819a0e1bab015 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Mon, 21 Sep 2020 04:40:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E6=B3=89=E5=B7=9E=E5=B8=82?= =?UTF-8?q?=E8=B7=A8=E5=A2=83=E7=94=B5=E5=AD=90=E5=95=86=E5=8A=A1=E5=8D=8F?= =?UTF-8?q?=E4=BC=9A=20(#5691)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Henry Wang --- docs/government.md | 12 +++++++++ lib/router.js | 3 +++ lib/routes/qzcea/index.js | 52 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 lib/routes/qzcea/index.js diff --git a/docs/government.md b/docs/government.md index 7ca063f443..206cd3aadd 100644 --- a/docs/government.md +++ b/docs/government.md @@ -71,6 +71,18 @@ pageClass: routes +## 泉州市跨境电子商务协会 + +### 新闻动态 + + + +| 新闻动态 | 协会动态 | 通知公告 | 会员风采 | 政策法规 | 电商资讯 | +| -------- | -------- | -------- | -------- | -------- | -------- | +| 1 | 2 | 3 | 5 | 14 | 18 | + + + ## 日本国外務省 ### 記者会見 diff --git a/lib/router.js b/lib/router.js index 64ed66efa4..aa68f1f37e 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3216,6 +3216,9 @@ router.get('/feixuew/:id?', require('./routes/feixuew/index')); // 1X router.get('/1x/:type?/:caty?', require('./routes/1x/index')); +// 泉州市跨境电子商务协会 +router.get('/qzcea/:caty?', require('./routes/qzcea/index')); + // 福利年 router.get('/fulinian/:caty?', require('./routes/fulinian/index')); diff --git a/lib/routes/qzcea/index.js b/lib/routes/qzcea/index.js new file mode 100644 index 0000000000..7d470fd727 --- /dev/null +++ b/lib/routes/qzcea/index.js @@ -0,0 +1,52 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + ctx.params.caty = ctx.params.caty || '1'; + + const rootUrl = 'http://www.qzcea.org'; + const currentUrl = `${rootUrl}/usernewscatname_nc${ctx.params.caty}`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + $('a.news-more').remove(); + + const list = $('li.clearfix div.news-right a') + .slice(0, 10) + .map((_, item) => { + item = $(item); + return { + title: item.text(), + link: `${rootUrl}${item.attr('href')}`, + pubDate: new Date(item.next().text().replace('时间 :', '') + ' GMT+8').toUTCString(), + }; + }) + .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.newm').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${$('title').text()} - 泉州市跨境电子商务协会`, + link: currentUrl, + item: items, + }; +};