feat: 优化sketch beta对已发布的情况输出item信息. (#3127)
This commit is contained in:
+90
-10
@@ -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(),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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: `<img class="sketch-logo" src="https://cdn.sketchapp.com/assets/components/block-buy/logo.png"
|
||||
srcset="https://cdn.sketchapp.com/assets/components/block-buy/logo.png 1x, https://cdn.sketchapp.com/assets/components/block-buy/logo@2x.png 2x"
|
||||
alt="Sketch Logo">${item.find('section.update-highlights .lead').html()}<br>
|
||||
description: `${item.find('section.update-highlights .lead').html()}<br>
|
||||
${item.find('section.update-highlights footer').html()}<br>
|
||||
${item.find('aside.update-details .mask').html()}`,
|
||||
link: `https://www.sketch.com/updates/${item.find('.update-version-title a').attr('href')}`,
|
||||
|
||||
Reference in New Issue
Block a user