From c91ec137ea99427cc33d1440333b01e871096478 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Mon, 2 Nov 2020 19:19:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E7=A7=91=E6=8A=80=E5=B3=B6?= =?UTF-8?q?=E8=AE=80=20(#6078)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/new-media.md | 12 +++++++++ lib/router.js | 3 +++ lib/routes/daodu/index.js | 52 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 lib/routes/daodu/index.js diff --git a/docs/new-media.md b/docs/new-media.md index 118c9e41d..42925d43a 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -981,6 +981,18 @@ column 为 third 时可选的 category: +## 科技島讀 + +### 分類 + + + +| 全部 | 文章 | Podcast | +| ---- | ------- | ------- | +| all | article | podcast | + + + ## 快科技(原驱动之家) ### 最新新闻 diff --git a/lib/router.js b/lib/router.js index 43ae5155e..7fdb3c0f1 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3453,6 +3453,9 @@ router.get('/wsj/:lang/:category', require('./routes/wsj/index')); // China File router.get('/chinafile/:category?', require('./routes/chinafile/index')); +// 科技島讀 +router.get('/daodu/:caty?', require('./routes/daodu/index')); + // CNTV router.get('/cntv/:column', require('./routes/cntv/cntv')); diff --git a/lib/routes/daodu/index.js b/lib/routes/daodu/index.js new file mode 100644 index 000000000..e22c84e8d --- /dev/null +++ b/lib/routes/daodu/index.js @@ -0,0 +1,52 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const caty = ctx.params.caty || 'all'; + + const rootUrl = 'https://daodu.tech'; + const currentUrl = `${rootUrl}${caty === 'all' ? '' : '/archive_' + caty}`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('h2[itemprop="headline"] a, .post-header .archive__article__title a') + .slice(0, 15) + .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); + + content('.member-only').remove(); + + item.description = content('.post-entry-text').html(); + item.pubDate = new Date(content('meta[property="article:published_time"]').attr('content')).toUTCString(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text().replace('一覽表', ''), + link: currentUrl, + item: items, + }; +};