From 757708ca9503f70692371c3b16f529aadf6bbcd9 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Mon, 24 Aug 2020 19:23:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E6=B4=9B=E8=B0=B7=E6=97=A5?= =?UTF-8?q?=E6=8A=A5=E6=96=87=E7=AB=A0=E5=85=A8=E6=96=87=20(#5503)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/programming.md | 6 ++---- lib/routes/luogu/daily.js | 30 ++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/docs/programming.md b/docs/programming.md index 4f5b39997..85d117caa 100644 --- a/docs/programming.md +++ b/docs/programming.md @@ -564,13 +564,11 @@ GitHub 官方也提供了一些 RSS: ### 日报 - - + ### 近期比赛 - - + ## 码农俱乐部 diff --git a/lib/routes/luogu/daily.js b/lib/routes/luogu/daily.js index eb1e2133d..4fb9ce95f 100644 --- a/lib/routes/luogu/daily.js +++ b/lib/routes/luogu/daily.js @@ -13,16 +13,42 @@ module.exports = async (ctx) => { .map(function () { const info = { title: $(this).find('strong').text() || $(this).text(), - description: $(this).html(), link: $(this).find('a').attr('href'), }; return info; }) .get(); + const items = await Promise.all( + out.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); + const timeRegExp = new RegExp(/(?<=([1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\s+(20|21|22|23|[0-1]\d):[0-5]\d:[0-5]\d))/); + + item.description = content('#article-content').html(); + + content('#article-content').remove(); + + const line = content + .html() + .split('\n') + .find((line) => timeRegExp.test(line)); + + item.pubDate = new Date(line.match(timeRegExp)[1] + ' GMT+8').toUTCString(); + + return item; + }) + ) + ); + ctx.state.data = { title: title, link: link, - item: out, + item: items, }; };