From df8beee2f03e6f73765932b6716075d6309bb956 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Mon, 18 Jan 2021 04:51:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E5=9F=8E=E5=86=9C=20Growin'=20Ci?= =?UTF-8?q?ty=20=E5=9F=8E=E5=86=9C=E8=B5=84=E8=AE=AF=E8=A7=82=E7=82=B9=20(?= =?UTF-8?q?#6715)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/new-media.md | 24 +++++++++++++++++ lib/router.js | 3 +++ lib/routes/growincity/news.js | 50 +++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 lib/routes/growincity/news.js diff --git a/docs/new-media.md b/docs/new-media.md index 6570059bd..d846a2c27 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -774,6 +774,30 @@ Supported sub-sites: +## 城农 Growin' City + +### 城农资讯观点 + + + +| 原创内容 | 商业投资 | 观点评论 | 农业科技 | +| -------- | -------- | -------- | -------- | +| 48 | 55 | 88 | 98 | + +| 农艺管理 | 农业机械 | 设施农业 | 畜牧水产 | +| -------- | -------- | -------- | -------- | +| 101 | 83 | 85 | 87 | + +| 食品科技 | 科技产品 | 食品创新 | 研究报告 | +| -------- | -------- | -------- | -------- | +| 86 | 100 | 99 | 76 | + +| 教育拓展 | 展会培训 | 业界访谈 | +| -------- | -------- | -------- | +| 61 | 77 | 72 | + + + ## 抽屉新热榜 ### 最新 diff --git a/lib/router.js b/lib/router.js index ff58e7e07..ea0cf2af0 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3888,4 +3888,7 @@ router.get('/chiculture/topic/:category?', require('./routes/chiculture/topic')) router.get('/cqut/news', require('./routes/universities/cqut/cqut-news')); router.get('/cqut/libnews', require('./routes/universities/cqut/cqut-libnews')); +// 城农 Growin' City +router.get('/growincity/news/:id?', require('./routes/growincity/news')); + module.exports = router; diff --git a/lib/routes/growincity/news.js b/lib/routes/growincity/news.js new file mode 100644 index 000000000..505b6d252 --- /dev/null +++ b/lib/routes/growincity/news.js @@ -0,0 +1,50 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const id = ctx.params.id || '48'; + + const rootUrl = 'http://www.growincity.com'; + const currentUrl = `${rootUrl}?page_id=11112&qfyuuid=qfy_posts_grid_s6lpz&q_term=${id}&q_type=post`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.link_title') + .slice(0, 10) + .map((_, item) => { + item = $(item); + return { + title: item.text(), + link: 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); + + item.description = content('div[qfyuuid="qfy_column_text_view_rgnpn"]').html(); + item.pubDate = new Date(detailResponse.data.match(/>发布时间:<\/span>(\d{4}-\d{2}-\d{2} \d{2}:\d{2})/)[1]).toUTCString(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: "城农资讯观点 - 城农 Growin' City", + link: currentUrl, + item: items, + }; +};