From b75ea3981fc399fc398b41033b8de7170534ce39 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Tue, 26 May 2020 11:25:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E8=87=B4=E7=BE=8E=E5=8C=96?= =?UTF-8?q?=E6=9C=80=E6=96=B0=E4=B8=BB=E9=A2=98=20(#4850)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/picture.md | 6 ++++++ lib/router.js | 3 +++ lib/routes/zhutix/latest.js | 42 +++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 lib/routes/zhutix/latest.js diff --git a/docs/picture.md b/docs/picture.md index 1011ab900..fd0c44e99 100644 --- a/docs/picture.md +++ b/docs/picture.md @@ -232,3 +232,9 @@ pageClass: routes ### 用户上传作品和用户喜欢作品 + +## 致美化 + +### 最新主题 + + diff --git a/lib/router.js b/lib/router.js index 6cf467481..a0bee8988 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2756,4 +2756,7 @@ router.get('/pbc/tradeAnnouncement', require('./routes/pbc/tradeAnnouncement')); // Monotype router.get('/monotype/article', require('./routes/monotype/article')); +// 致美化 +router.get('/zhutix/latest', require('./routes/zhutix/latest')); + module.exports = router; diff --git a/lib/routes/zhutix/latest.js b/lib/routes/zhutix/latest.js new file mode 100644 index 000000000..90053fc03 --- /dev/null +++ b/lib/routes/zhutix/latest.js @@ -0,0 +1,42 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const currentUrl = 'https://zhutix.com/'; + const response = await got({ + method: 'get', + url: currentUrl, + }); + const $ = cheerio.load(response.data); + const list = $('#main div.grid-bor div.content-card') + .slice(0, 10) + .map((_, item) => { + item = $(item); + const a = item.find('a'); + return { + title: a.text(), + link: a.attr('href'), + pubDate: new Date(item.find('i.feng-liulanjilu').parent().text()).toUTCString(), + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const res = await got({ method: 'get', url: item.link }); + const content = cheerio.load(res.data); + + item.description = content('#entry-content').html(); + return item; + }) + ) + ); + + ctx.state.data = { + title: '致美化 - 最新主题', + link: currentUrl, + item: items, + }; +};