Skip to content

Commit 579e419

Browse files
Jeason0228DIYgod
authored andcommitted
feat: 优化sketch beta对已发布的情况输出item信息. (#3127)
1 parent ad128da commit 579e419

File tree

2 files changed

+92
-14
lines changed

2 files changed

+92
-14
lines changed

lib/routes/sketch/beta.js

Lines changed: 90 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,100 @@ const cheerio = require('cheerio');
44
module.exports = async (ctx) => {
55
const response = await got({
66
method: 'get',
7+
// sudo apachectl start 本地服务器
8+
// web根目录在:/Library/WebServer/Documents
9+
// url: 'http://localhost/beta.html',
10+
// url: 'http://localhost/Released.html',
711
url: 'https://www.sketch.com/beta/',
812
});
913
const data = response.data;
1014
const $ = cheerio.load(data);
11-
const titledata = $('.update-details h4')
15+
// 判断是否已发布
16+
const releaseString = $('.wrapper')
1217
.first()
13-
.html();
14-
// const versiondata=Number(titledata.substr(-2));
15-
const content = $('.update-details').html();
18+
.find('h1')
19+
.text()
20+
.substr(-8);
21+
// console.log(releaseString);
22+
let isrelease = 0;
23+
if (releaseString === 'released') {
24+
isrelease = 1;
25+
} else {
26+
isrelease = 0;
27+
}
28+
// console.log(isrelease);
1629

17-
ctx.state.data = {
18-
title: titledata,
19-
link: response.url,
20-
description: content,
21-
allowEmpty: true,
22-
};
30+
const list = $('.wrapper').first();
31+
// sketch update 提供的时间 年月反了.要重新调整
32+
const pubday = list
33+
.find('.heading-caption time')
34+
.attr('datetime')
35+
.substr(0, 2);
36+
const pubmonth = list
37+
.find('.heading-caption time')
38+
.attr('datetime')
39+
.substr(3, 2);
40+
const pubyear = list
41+
.find('.heading-caption time')
42+
.attr('datetime')
43+
.substr(-4);
44+
const pubdateString = pubmonth + `-` + pubday + `-` + pubyear;
45+
46+
if (isrelease === 1) {
47+
// console.log("已经发布到正式版 ");
48+
ctx.state.data = {
49+
title: `Sketch Beta`,
50+
link: response.url,
51+
description: 'Sketch is a design toolkit built to help you create your best work — from your earliest ideas, through to final artwork.',
52+
image: 'https://cdn.sketchapp.com/assets/components/block-buy/logo.png',
53+
54+
item:
55+
list &&
56+
list
57+
.map((index, item) => {
58+
item = $(item);
59+
return {
60+
title: `${item
61+
.find('h1')
62+
.first()
63+
.text()}`,
64+
description: `${item.html()}`,
65+
link: `https://www.sketch.com/updates/`,
66+
pubDate: new Date(pubdateString).toLocaleDateString(),
67+
};
68+
})
69+
.get(),
70+
};
71+
} else {
72+
// console.log("Beta版本发布 ");
73+
const content = $('.update-details').html();
74+
ctx.state.data = {
75+
title: `Sketch Beta`,
76+
link: response.url,
77+
description: 'Sketch is a design toolkit built to help you create your best work — from your earliest ideas, through to final artwork.',
78+
image: 'https://cdn.sketchapp.com/assets/components/block-buy/logo.png',
79+
80+
item:
81+
list &&
82+
list
83+
.map((index, item) => {
84+
item = $(item);
85+
return {
86+
title: `${item
87+
.find('h1')
88+
.first()
89+
.text()}
90+
- ${item
91+
.find('small.heading-caption')
92+
.first()
93+
.text()
94+
.substr(16, 2)}`,
95+
description: content,
96+
link: `https://www.sketch.com/beta/`,
97+
pubDate: new Date(pubdateString).toLocaleDateString(),
98+
};
99+
})
100+
.get(),
101+
};
102+
}
23103
};

lib/routes/sketch/updates.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = async (ctx) => {
1313
ctx.state.data = {
1414
title: 'Sketch Release版本',
1515
link: response.url,
16-
description: $('meta[name="description"]').attr('content'),
16+
description: 'Sketch is a design toolkit built to help you create your best work — from your earliest ideas, through to final artwork.',
1717
image: 'https://cdn.sketchapp.com/assets/components/block-buy/logo.png',
1818

1919
item:
@@ -41,9 +41,7 @@ module.exports = async (ctx) => {
4141
.find('h2.update-version-title')
4242
.first()
4343
.text()}`,
44-
description: `<img class="sketch-logo" src="https://cdn.sketchapp.com/assets/components/block-buy/logo.png"
45-
srcset="https://cdn.sketchapp.com/assets/components/block-buy/logo.png 1x, https://cdn.sketchapp.com/assets/components/block-buy/[email protected] 2x"
46-
alt="Sketch Logo">${item.find('section.update-highlights .lead').html()}<br>
44+
description: `${item.find('section.update-highlights .lead').html()}<br>
4745
${item.find('section.update-highlights footer').html()}<br>
4846
${item.find('aside.update-details .mask').html()}`,
4947
link: `https://www.sketch.com/updates/${item.find('.update-version-title a').attr('href')}`,

0 commit comments

Comments
 (0)