Skip to content

Commit

Permalink
feat(route): add TradingView Desktop releases and release notes (#14234)
Browse files Browse the repository at this point in the history
  • Loading branch information
nczitzk authored Jan 14, 2024
1 parent 9dc7e52 commit 376ebf4
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
61 changes: 61 additions & 0 deletions lib/v2/tradingview/desktop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');

module.exports = async (ctx) => {
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 50;

const rootUrl = 'https://www.tradingview.com';
const currentUrl = new URL('/support/solutions/43000673888-tradingview-desktop-releases-and-release-notes/', rootUrl).href;

const { data: response } = await got(currentUrl);

const $ = cheerio.load(response);

$('h4[data-identifyelement]').each((_, el) => {
el = $(el);

if (el.text().trim() === '') {
el.remove();
}
});

const items = $('h4[data-identifyelement]')
.toArray()
.slice(0, limit)
.map((item) => {
item = $(item);

const title = item.text();
const description = $.html(item.nextUntil('h4'));
const content = cheerio.load(description);

return {
title,
link: currentUrl,
description,
category: content('h5')
.toArray()
.map((c) => $(c).text()),
guid: `tradingview-desktop#${title.split(/versions?\s/).pop()}`,
pubDate: timezone(parseDate(title.split(/\./)[0], 'MMMM D, YYYY'), +8),
};
});

const title = $('title').text();
const titleSplits = title.split(//);
const icon = new URL($('link[rel="icon"]').prop('href'), rootUrl).href;

ctx.state.data = {
item: items,
title,
link: currentUrl,
description: titleSplits[0],
language: $('html').prop('lang'),
icon,
logo: icon,
subtitle: titleSplits[0],
author: titleSplits.pop(),
};
};
1 change: 1 addition & 0 deletions lib/v2/tradingview/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
'/blog/:language?/category/:category?': ['nczitzk'],
'/desktop': ['nczitzk'],
};
6 changes: 6 additions & 0 deletions lib/v2/tradingview/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ module.exports = {
source: ['/blog/:language/category/widgets/'],
target: '/tradingview/blog/:language/category/widgets',
},
{
title: 'Desktop releases and release notes',
docs: 'https://docs.rsshub.app/routes/program-update#tradingview-desktop-releases-and-release-notes',
source: ['/support/solutions/43000673888-tradingview-desktop-releases-and-release-notes/'],
target: '/tradingview/desktop',
},
],
},
};
1 change: 1 addition & 0 deletions lib/v2/tradingview/router.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = function (router) {
router.get('/blog/:category*', require('./blog'));
router.get('/desktop', require('./desktop'));
};
4 changes: 4 additions & 0 deletions website/docs/routes/program-update.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,10 @@ Logseq 开发团队已经放弃了 [旧网站](https://logseq.com/blog)。
| [Widgets](https://www.tradingview.com/blog/en/category/widgets/) | category/widgets |
</Route>

### Desktop releases and release notes {#tradingview-desktop-releases-and-release-notes}

<Route author="nczitzk" example="/tradingview/desktop" path="/tradingview/desktop" radar="1" />

## Typora {#typora}

### Changelog {#typora-changelog}
Expand Down

0 comments on commit 376ebf4

Please sign in to comment.