From 0830f401de3b1a3543017f1decdabeedd86f9936 Mon Sep 17 00:00:00 2001 From: Jeason0228 <44083849+Jeason0228@users.noreply.github.com> Date: Thu, 19 Sep 2019 15:10:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E5=AF=B9Sketch=20?= =?UTF-8?q?=E6=AD=A3=E5=BC=8F=E7=89=88=E7=9A=84RSS=20=E6=94=AF=E6=8C=81=20?= =?UTF-8?q?(#3109)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/program-update.md | 4 +++ lib/router.js | 3 ++ lib/routes/sketch/updates.js | 56 ++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 lib/routes/sketch/updates.js diff --git a/docs/program-update.md b/docs/program-update.md index 8d4373cb4..a65528813 100644 --- a/docs/program-update.md +++ b/docs/program-update.md @@ -128,6 +128,10 @@ pageClass: routes +### Release 更新 + + + ## Thunderbird ### 更新日志 diff --git a/lib/router.js b/lib/router.js index 514c1b53d..a416e6557 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1111,8 +1111,11 @@ router.get('/nowcoder/discuss/:type/:order', require('./routes/nowcoder/discuss' // Xiaomi.eu router.get('/xiaomieu/releases', require('./routes/xiaomieu/releases')); + // sketch.com router.get('/sketch/beta', require('./routes/sketch/beta')); +router.get('/sketch/updates', require('./routes/sketch/updates')); + // 每日安全 router.get('/security/pulses', require('./routes/security/pulses')); diff --git a/lib/routes/sketch/updates.js b/lib/routes/sketch/updates.js new file mode 100644 index 000000000..d13f5a643 --- /dev/null +++ b/lib/routes/sketch/updates.js @@ -0,0 +1,56 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const response = await got({ + method: 'get', + url: 'https://cdn.sketchapp.com/releases.html', + }); + const data = response.data; + const $ = cheerio.load(data); + const list = $('div.update'); + + ctx.state.data = { + title: 'Sketch Release版本', + link: response.url, + description: $('meta[name="description"]').attr('content'), + image: 'https://cdn.sketchapp.com/assets/components/block-buy/logo.png', + + item: + list && + list + .map((index, item) => { + item = $(item); + // sketch update 提供的时间 年月反了.要重新调整 + const pubday = item + .find('section.update-highlights time') + .attr('datetime') + .substr(0, 2); + const pubmonth = item + .find('section.update-highlights time') + .attr('datetime') + .substr(3, 2); + const pubyear = item + .find('section.update-highlights time') + .attr('datetime') + .substr(-4); + const pubdateString = pubmonth + `-` + pubday + `-` + pubyear; + + return { + title: `${item + .find('h2.update-version-title') + .first() + .text()}`, + description: `${item.find('section.update-highlights .lead').html()}
+ ${item.find('section.update-highlights footer').html()}
+ ${item.find('aside.update-details .mask').html()}`, + link: `https://www.sketch.com/updates/${item.find('.update-version-title a').attr('href')}`, + pubDate: new Date(pubdateString).toLocaleDateString(), + }; + }) + + .get(), + }; +};