From 28e226edb4dbe5b46899fbb9dd3a62b7df0e0ff5 Mon Sep 17 00:00:00 2001 From: Naiqus Zhang Date: Thu, 30 May 2019 05:57:23 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20WIRED=E6=9D=82=E5=BF=97=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E6=A0=87=E7=AD=BE=E8=AE=A2=E9=98=85=20(#2262)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 增加连线wired根据标签订阅功能 * 在README中添加路由介绍 Co-authored-by: Suqian Zhang --- docs/traditional-media.md | 10 ++++++++++ lib/router.js | 3 +++ lib/routes/wired/tag.js | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 lib/routes/wired/tag.js diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 48f435368..6bf8043e7 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -337,3 +337,13 @@ category 对应的关键词有 | 资讯 | 风景 | 体验 | 交通 | + +## 连线 Wired + +非订阅用户每月有阅读全文次数限制。 + +### 标签 + + + + diff --git a/lib/router.js b/lib/router.js index 13c1e0fa5..29378c10f 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1319,6 +1319,9 @@ router.get('/curseforge/:gameid/:catagoryid/:projectid/files', require('./routes // 西南财经大学 router.get('/swufe/seie/:type?', require('./routes/universities/swufe/seie')); +// Wired +router.get('/wired/tag/:tag', require('./routes/wired/tag')); + // 语雀文档 router.get('/yuque/doc/:repo_id', require('./routes/yuque/doc')); diff --git a/lib/routes/wired/tag.js b/lib/routes/wired/tag.js new file mode 100644 index 000000000..d229f35f7 --- /dev/null +++ b/lib/routes/wired/tag.js @@ -0,0 +1,39 @@ +const axios = require('@/utils/axios'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const url = `https://www.wired.com/tag/${ctx.params.tag}/page`; + + const response = await axios({ + method: 'get', + url, + }); + + const $ = cheerio.load(response.data); + const list = $('.archive-list-component__items li'); + + const posts = list + .map((index_, content_) => ({ + title: $(content_) + .find('.archive-item-component__title') + .text(), + description: ` +
+ ${$(content_) + .find('.archive-item-component__desc') + .text()}`, + link: `https://www.wired.com${$(content_) + .find('.archive-item-component__link') + .attr('href')}`, + })) + .get(); + + ctx.state.data = { + title: `Wired - ${ctx.params.tag}`, + link: url, + item: posts, + }; +};