From 579e41980802f4a03fe795aa7e9cd54b8e6fd17e Mon Sep 17 00:00:00 2001
From: Jeason0228 <44083849+Jeason0228@users.noreply.github.com>
Date: Mon, 23 Sep 2019 17:23:38 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96sketch=20beta?=
=?UTF-8?q?=E5=AF=B9=E5=B7=B2=E5=8F=91=E5=B8=83=E7=9A=84=E6=83=85=E5=86=B5?=
=?UTF-8?q?=E8=BE=93=E5=87=BAitem=E4=BF=A1=E6=81=AF.=20(#3127)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/routes/sketch/beta.js | 100 +++++++++++++++++++++++++++++++----
lib/routes/sketch/updates.js | 6 +--
2 files changed, 92 insertions(+), 14 deletions(-)
diff --git a/lib/routes/sketch/beta.js b/lib/routes/sketch/beta.js
index 5bba03e02..19af54e68 100644
--- a/lib/routes/sketch/beta.js
+++ b/lib/routes/sketch/beta.js
@@ -4,20 +4,100 @@ const cheerio = require('cheerio');
module.exports = async (ctx) => {
const response = await got({
method: 'get',
+ // sudo apachectl start 本地服务器
+ // web根目录在:/Library/WebServer/Documents
+ // url: 'http://localhost/beta.html',
+ // url: 'http://localhost/Released.html',
url: 'https://www.sketch.com/beta/',
});
const data = response.data;
const $ = cheerio.load(data);
- const titledata = $('.update-details h4')
+ // 判断是否已发布
+ const releaseString = $('.wrapper')
.first()
- .html();
- // const versiondata=Number(titledata.substr(-2));
- const content = $('.update-details').html();
+ .find('h1')
+ .text()
+ .substr(-8);
+ // console.log(releaseString);
+ let isrelease = 0;
+ if (releaseString === 'released') {
+ isrelease = 1;
+ } else {
+ isrelease = 0;
+ }
+ // console.log(isrelease);
- ctx.state.data = {
- title: titledata,
- link: response.url,
- description: content,
- allowEmpty: true,
- };
+ const list = $('.wrapper').first();
+ // sketch update 提供的时间 年月反了.要重新调整
+ const pubday = list
+ .find('.heading-caption time')
+ .attr('datetime')
+ .substr(0, 2);
+ const pubmonth = list
+ .find('.heading-caption time')
+ .attr('datetime')
+ .substr(3, 2);
+ const pubyear = list
+ .find('.heading-caption time')
+ .attr('datetime')
+ .substr(-4);
+ const pubdateString = pubmonth + `-` + pubday + `-` + pubyear;
+
+ if (isrelease === 1) {
+ // console.log("已经发布到正式版 ");
+ ctx.state.data = {
+ title: `Sketch Beta`,
+ link: response.url,
+ description: 'Sketch is a design toolkit built to help you create your best work — from your earliest ideas, through to final artwork.',
+ image: 'https://cdn.sketchapp.com/assets/components/block-buy/logo.png',
+
+ item:
+ list &&
+ list
+ .map((index, item) => {
+ item = $(item);
+ return {
+ title: `${item
+ .find('h1')
+ .first()
+ .text()}`,
+ description: `${item.html()}`,
+ link: `https://www.sketch.com/updates/`,
+ pubDate: new Date(pubdateString).toLocaleDateString(),
+ };
+ })
+ .get(),
+ };
+ } else {
+ // console.log("Beta版本发布 ");
+ const content = $('.update-details').html();
+ ctx.state.data = {
+ title: `Sketch Beta`,
+ link: response.url,
+ description: 'Sketch is a design toolkit built to help you create your best work — from your earliest ideas, through to final artwork.',
+ image: 'https://cdn.sketchapp.com/assets/components/block-buy/logo.png',
+
+ item:
+ list &&
+ list
+ .map((index, item) => {
+ item = $(item);
+ return {
+ title: `${item
+ .find('h1')
+ .first()
+ .text()}
+ - ${item
+ .find('small.heading-caption')
+ .first()
+ .text()
+ .substr(16, 2)}`,
+ description: content,
+ link: `https://www.sketch.com/beta/`,
+ pubDate: new Date(pubdateString).toLocaleDateString(),
+ };
+ })
+ .get(),
+ };
+ }
};
diff --git a/lib/routes/sketch/updates.js b/lib/routes/sketch/updates.js
index d13f5a643..33b524799 100644
--- a/lib/routes/sketch/updates.js
+++ b/lib/routes/sketch/updates.js
@@ -13,7 +13,7 @@ module.exports = async (ctx) => {
ctx.state.data = {
title: 'Sketch Release版本',
link: response.url,
- description: $('meta[name="description"]').attr('content'),
+ description: 'Sketch is a design toolkit built to help you create your best work — from your earliest ideas, through to final artwork.',
image: 'https://cdn.sketchapp.com/assets/components/block-buy/logo.png',
item:
@@ -41,9 +41,7 @@ module.exports = async (ctx) => {
.find('h2.update-version-title')
.first()
.text()}`,
- description: `
${item.find('section.update-highlights .lead').html()}
+ 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')}`,