From b29ef8f941d7ab78d418fec2d2576470087cabe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=89=E5=87=89?= Date: Tue, 6 Nov 2018 20:17:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0:=20=E6=8A=80=E6=9C=AF?= =?UTF-8?q?=E5=A4=B4=E6=9D=A1=20(#1077)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 增加:有品-每日上新 * 修复 summary 字段错误 * 将 youpin 模块转移至 mi 目录下,并更新文档 * 增加: 技术头条 --- docs/README.md | 4 ++++ router.js | 3 +++ routes/blogread/newest.js | 42 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 routes/blogread/newest.js diff --git a/docs/README.md b/docs/README.md index c7a72b9b4..621ddaa1f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -730,6 +730,10 @@ GitHub 官方也提供了一些 RSS: +### 技术头条 + + + ## 直播 ### 哔哩哔哩直播 diff --git a/router.js b/router.js index 1e63fa766..767e0cb8c 100644 --- a/router.js +++ b/router.js @@ -753,6 +753,9 @@ router.get('/hko/weather', require('./routes/hko/weather')); // sankakucomplex router.get('/sankakucomplex/post', require('./routes/sankakucomplex/post')); +// 技术头条 +router.get('/blogread/newest', require('./routes/blogread/newest')); + // gnn游戏新闻 router.get('/gnn/gnn', require('./routes/gnn/gnn')); diff --git a/routes/blogread/newest.js b/routes/blogread/newest.js new file mode 100644 index 000000000..9af3e8d5c --- /dev/null +++ b/routes/blogread/newest.js @@ -0,0 +1,42 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const url = 'http://blogread.cn/news/newest.php'; + const response = await axios({ + method: 'get', + url, + }); + const $ = cheerio.load(response.data); + const resultItem = $('.media') + .map((index, elem) => { + elem = $(elem); + const $link = elem.find('dt a'); + const pubDate = elem + .find('.small') + .text() + .match(/\s[0-9-]+\s[0-9:]+\s/g)[0] + .trim(); + + return { + title: $link.text(), + description: elem + .find('dd') + .eq(0) + .text(), + link: $link.attr('href'), + pubDate: new Date(pubDate).toUTCString(), + author: elem + .find('.small a') + .eq(0) + .text(), + }; + }) + .get(); + + ctx.state.data = { + title: '技术头条', + link: url, + item: resultItem, + }; +};