Files
RSSHub/lib/routes/sketch/beta.js

110 lines
3.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const got = require('@/utils/got');
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 version = $('small.heading-caption')
.text()
.trim();
// console.log(version);
// 判断是否已发布
const releaseString = $('.wrapper')
.first()
.find('h1')
.text()
.substr(-8);
// console.log(releaseString);
let isrelease = 0;
if (releaseString === 'released') {
isrelease = 1;
} else {
isrelease = 0;
}
// console.log(isrelease);
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(),
guid: version,
};
})
.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(),
guid: version,
};
})
.get(),
};
}
};