From 150883ca142ec7e29a486d24e4cd714ecfdcda43 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sun, 27 Jun 2021 08:01:25 +0800 Subject: [PATCH] =?UTF-8?q?feat(add):=20=E6=B7=B1=E5=9C=B3=E6=96=B0?= =?UTF-8?q?=E9=97=BB=E7=BD=91=E6=B7=B1=E5=9C=B3=E5=B8=82=E6=94=BF=E5=BA=9C?= =?UTF-8?q?=E6=96=B0=E9=97=BB=E5=8F=91=E5=B8=83=E5=8E=85=20(#7733)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/new-media.md | 4 +++ lib/router.js | 1 + lib/routes/sznews/press.js | 51 ++++++++++++++++++++++++++++++++++++ lib/routes/sznews/ranking.js | 2 +- 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 lib/routes/sznews/press.js diff --git a/docs/new-media.md b/docs/new-media.md index 6188e4ff87..3b704a715e 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1806,6 +1806,10 @@ column 为 third 时可选的 category: ## 深圳新闻网 +### 深圳市政府新闻发布厅 + + + ### 排行榜 diff --git a/lib/router.js b/lib/router.js index 19356da1db..2785a0347d 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3964,6 +3964,7 @@ router.get('/babehub/search/:keyword?', require('./routes/babehub/search')); router.get('/babehub/:category?', require('./routes/babehub/index')); // 深圳新闻网 +router.get('/sznews/press', require('./routes/sznews/press')); router.get('/sznews/ranking', require('./routes/sznews/ranking')); // Shuax diff --git a/lib/routes/sznews/press.js b/lib/routes/sznews/press.js new file mode 100644 index 0000000000..b83bd41967 --- /dev/null +++ b/lib/routes/sznews/press.js @@ -0,0 +1,51 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const timezone = require('@/utils/timezone'); + +module.exports = async (ctx) => { + const rootUrl = 'http://www.sznews.com'; + const currentUrl = `${rootUrl}/zhuanti/node_210611.htm`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.list-pt-li a h3') + .slice(0, 10) + .map((_, item) => { + item = $(item).parent(); + + return { + title: item.text(), + link: item.attr('href'), + pubDate: timezone(new Date(item.parent().find('.date').text()), +8), + }; + }) + .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('#picBox').html() + content('.pos').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: '往期回顾 - 深圳市政府新闻发布厅', + link: currentUrl, + item: items, + }; +}; diff --git a/lib/routes/sznews/ranking.js b/lib/routes/sznews/ranking.js index 7a36f5cdc8..1834157944 100644 --- a/lib/routes/sznews/ranking.js +++ b/lib/routes/sznews/ranking.js @@ -42,7 +42,7 @@ module.exports = async (ctx) => { item.description = content('.article-content').html(); item.author = content('.a_source').text().replace('来源: ', ''); - item.pubDate = new Date(content('.a_time').text() + ' GMT+8').toUTCString(); + item.pubDate = Date.parse(content('.a_time').text()); return item; })