Skip to content

Commit

Permalink
fix(route): typora (DIYgod#11578)
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyRL authored Jan 8, 2023
1 parent 7e3e034 commit 09bfe77
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 100 deletions.
6 changes: 5 additions & 1 deletion docs/en/program-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,11 @@ Language

### Changelog

<RouteEn author="cnzgray" example="/typora/changelog" path="/typora/changelog"/>
<RouteEn author="cnzgray" example="/typora/changelog" path="/typora/changelog" radar="1"/>

### Dev Release Changelog

<RouteEn author="nczitzk" example="/typora/changelog/dev" path="/typora/changelog/dev" radar="1"/>

## VMware

Expand Down
4 changes: 2 additions & 2 deletions docs/program-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -615,11 +615,11 @@ Logseq 开发团队已经放弃了 [旧网站](https://logseq.com/blog)。

### Changelog

<Route author="cnzgray" example="/typora/changelog" path="/typora/changelog"/>
<Route author="cnzgray" example="/typora/changelog" path="/typora/changelog" radar="1"/>

### Dev Release Changelog

<Route author="nczitzk" example="/typora/changelog-dev/macOS" path="/typora/changelog-dev/:os" :paramsDesc="['操作系统类型, 可选 `macOS` 或 `Windows` 与 `Linux`,默认为 `macOS`']"/>
<Route author="nczitzk" example="/typora/changelog/dev" path="/typora/changelog/dev" radar="1"/>

## VMware

Expand Down
4 changes: 2 additions & 2 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -1023,8 +1023,8 @@ router.get('/tits-guru/category/:type', lazyloadRouteHandler('./routes/titsguru/
router.get('/tits-guru/model/:name', lazyloadRouteHandler('./routes/titsguru/model'));

// typora
router.get('/typora/changelog', lazyloadRouteHandler('./routes/typora/changelog'));
router.get('/typora/changelog-dev/:os?', lazyloadRouteHandler('./routes/typora/changelog-dev'));
// router.get('/typora/changelog', lazyloadRouteHandler('./routes/typora/changelog'));
// router.get('/typora/changelog-dev/:os?', lazyloadRouteHandler('./routes/typora/changelog-dev'));

// TSSstatus
router.get('/tssstatus/:board/:build', lazyloadRouteHandler('./routes/tssstatus'));
Expand Down
35 changes: 0 additions & 35 deletions lib/routes/typora/changelog-dev.js

This file was deleted.

60 changes: 0 additions & 60 deletions lib/routes/typora/changelog.js

This file was deleted.

31 changes: 31 additions & 0 deletions lib/v2/typora/changelog-dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');

module.exports = async (ctx) => {
const currentUrl = 'https://typora.io/releases/dev';
const response = await got(currentUrl);

const $ = cheerio.load(response.data);

const items = $('h2')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.text(),
link: `${currentUrl}#${item.text()}`,
description: item
.nextUntil('h2')
.toArray()
.map((item) => $(item).html())
.join(''),
};
});

ctx.state.data = {
title: `Typora Changelog - Dev`,
link: currentUrl,
description: 'Typora Changelog',
item: items,
};
};
40 changes: 40 additions & 0 deletions lib/v2/typora/changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');

module.exports = async (ctx) => {
const host = 'https://support.typora.io';

const { data } = await got(`${host}/store/`);

const list = Object.values(data)
.filter((i) => i.category === 'new')
.map((i) => ({
title: i.title,
author: i.author,
description: i.content,
link: `${host}${i.url}`,
}));

const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data } = await got(item.link);
const $ = cheerio.load(data);

item.pubDate = parseDate($('.post-meta time').text());
item.description = $('#post-content').html();

return item;
})
)
);

ctx.state.data = {
title: 'Typora Changelog',
link: host,
description: 'Typora Changelog',
image: `${host}/assets/img/favicon-128.png`,
item: items,
};
};
4 changes: 4 additions & 0 deletions lib/v2/typora/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
'/changelog': ['cnzgray'],
'/changelog/dev': ['nczitzk'],
};
21 changes: 21 additions & 0 deletions lib/v2/typora/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
'typora.io': {
_name: 'Typora',
'.': [
{
title: 'Dev Release Changelog',
docs: 'https://docs.rsshub.app/program-update.html#typora',
source: ['/releases/dev'],
target: '/typora/changelog/dev',
},
],
support: [
{
title: 'Changelog',
docs: 'https://docs.rsshub.app/program-update.html#typora',
source: ['/'],
target: '/typora/changelog',
},
],
},
};
4 changes: 4 additions & 0 deletions lib/v2/typora/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = (router) => {
router.get('/changelog', require('./changelog'));
router.get('/changelog/dev', require('./changelog-dev'));
};

0 comments on commit 09bfe77

Please sign in to comment.