feat: add typora dev release changelog (#5559)

This commit is contained in:
Ethan Shen 2020-08-30 11:02:23 +08:00 committed by GitHub
parent e1f5d25306
commit 34165f615b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 0 deletions

View File

@ -234,6 +234,10 @@ pageClass: routes
<Route author="cnzgray" example="/typora/changelog" path="/typora/changelog"/>
### Dev Release Changelog
<Route author="nczitzk" example="/typora/changelog-dev/macOS" path="/typora/changelog-dev/:os" :paramsDesc="['操作系统类型, 可选 `macOS``Windows``Linux`,默认为 `macOS`']"/>
## xclient.info
### 应用更新

View File

@ -1070,6 +1070,7 @@ router.get('/tits-guru/model/:name', require('./routes/titsguru/model'));
// typora
router.get('/typora/changelog', require('./routes/typora/changelog'));
router.get('/typora/changelog-dev/:os?', require('./routes/typora/changelog-dev'));
// TSSstatus
router.get('/tssstatus/:board/:build', require('./routes/tssstatus'));

View File

@ -0,0 +1,35 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
ctx.params.os = ctx.params.os || 'macos';
const currentUrl = `https://typora.io${ctx.params.os.toLowerCase() === 'macos' ? '' : '/windows'}/dev_release.html`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data.replace(/<h4>/g, '</div><div><h4>'));
const items = $('div')
.slice(0, 10)
.map((_, item) => {
item = $(item);
const h4 = item.find('h4');
h4.remove();
return {
title: h4.text(),
link: currentUrl,
description: item.html(),
};
})
.get();
ctx.state.data = {
title: `Typora Changelog - ${ctx.params.os.toLowerCase() === 'macos' ? 'macOS' : 'Windows/Linux'}`,
link: currentUrl,
description: 'Typora Changelog',
item: items,
};
};