From 4e5f50fe56849ff53f8f379fc46ce6febf22591f Mon Sep 17 00:00:00 2001 From: zengxs Date: Tue, 7 May 2019 12:08:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20OSChina=20=E6=96=B0=E9=97=BB=E6=8A=93?= =?UTF-8?q?=E5=8F=96=E7=9A=84=E6=97=B6=E5=80=99=E8=A7=A3=E6=9E=90=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E5=AD=97=E7=AC=A6=E4=B8=B2=20(#2062)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/oschina/news.js | 2 ++ lib/utils/date.js | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/routes/oschina/news.js b/lib/routes/oschina/news.js index b6109835a..069c4fcf7 100644 --- a/lib/routes/oschina/news.js +++ b/lib/routes/oschina/news.js @@ -1,5 +1,6 @@ const url = require('url'); const axios = require('../../utils/axios'); +const date = require('../../utils/date'); const cheerio = require('cheerio'); const USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0'; @@ -60,6 +61,7 @@ module.exports = async (ctx) => { title: each.find('a', 'h3').attr('title'), description: each.find('p', '.description').text(), link: url.resolve('https://www.oschina.net', encodeURI(originalUrl)), + pubDate: date(each.find('.extra > .list > .item:nth-of-type(2)').text()), }; if (/^https?:\/\/www.oschina.net\/news\/.*$/.test(originalUrl)) { const key = 'oschina' + item.link; diff --git a/lib/utils/date.js b/lib/utils/date.js index 8ca957387..5b86e6e67 100644 --- a/lib/utils/date.js +++ b/lib/utils/date.js @@ -26,6 +26,9 @@ module.exports = (html, timeZone = -serverOffset) => { } else if (/昨天 (\d+):(\d+)/.exec(html)) { math = /昨天 (\d+):(\d+)/.exec(html); date = new Date(date.getFullYear(), date.getMonth(), date.getDate() - 1, math[1], math[2]); + } else if (/前天\s*(\d+):(\d+)/.exec(html)) { + math = /前天\s*(\d+):(\d+)/.exec(html); + date = new Date(date.getFullYear(), date.getMonth(), date.getDate() - 2, math[1], math[2]); } else if (/(\d+)年(\d+)月(\d+)日(\d+)时/.exec(html)) { math = /(\d+)年(\d+)月(\d+)日(\d+)时/.exec(html); date = new Date(parseInt(math[1]), parseInt(math[2]) - 1, parseInt(math[3]), parseInt(math[4])); @@ -38,6 +41,12 @@ module.exports = (html, timeZone = -serverOffset) => { } else if (/(\d+)-(\d+) (\d+):(\d+)/.exec(html)) { math = /(\d+)-(\d+) (\d+):(\d+)/.exec(html); date = new Date(date.getFullYear(), parseInt(math[1]) - 1, math[2], math[3], math[4]); + } else if (/(\d+)\/(\d+)\/(\d+)\s*(\d+):(\d+)/.exec(html)) { + math = /(\d+)\/(\d+)\/(\d+)\s*(\d+):(\d+)/.exec(html); + date = new Date(math[1], parseInt(math[2]) - 1, math[3], math[4], math[5]); + } else if (/(\d+)\/(\d+)\s*(\d+):(\d+)/.exec(html)) { + math = /(\d+)\/(\d+)\s*(\d+):(\d+)/.exec(html); + date = new Date(date.getFullYear(), parseInt(math[1]) - 1, math[2], math[3], math[4]); } else if (/(\d+)月(\d+)日 (\d+):(\d+)/.exec(html)) { math = /(\d+)月(\d+)日 (\d+):(\d+)/.exec(html); date = new Date(date.getFullYear(), parseInt(math[1]) - 1, math[2], math[3], math[4]);