Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): add TradingView Pine Script™ Release notes #14279

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions lib/v2/tradingview/pine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');

module.exports = async (ctx) => {
const { version = 'v5' } = ctx.params;
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 100;

Check warning

Code scanning / ESLint

Prefer `Number` static properties over global ones. Warning

Prefer Number.parseInt over parseInt.

const rootUrl = 'https://www.tradingview.com';
const currentUrl = new URL(`pine-script-docs/en/${version}/Release_notes.html`, rootUrl).href;

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

const $ = cheerio.load(response);

const items = $('div.section')
.toArray()
.filter((item) => {
item = $(item);

return /\w+-\d{4}/.test(item.prop('id'));
})
.slice(0, limit)
.map((item) => {
item = $(item);

const id = item.prop('id');
const title = item.find('a.toc-backref').first().text();
const link = new URL(item.find('a.headerlink').prop('href'), currentUrl).href;

item.children().first().remove();

return {
title,
link,
description: item.html(),
pubDate: parseDate(`${id.charAt(0).toUpperCase()}${id.slice(1)}`, 'MMMM-YYYY'),
};
});

const image = new URL('_images/Pine_Script_logo.svg', currentUrl).href;
const icon = new URL('favicon.ico', rootUrl).href;

ctx.state.data = {
item: items,
title: $('title').text(),
link: currentUrl,
description: $('div.text-logo').text(),
language: $('html').prop('lang'),
image,
icon,
logo: icon,
};
};
6 changes: 6 additions & 0 deletions lib/v2/tradingview/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ module.exports = {
source: ['/support/solutions/43000673888-tradingview-desktop-releases-and-release-notes/'],
target: '/tradingview/desktop',
},
{
title: 'Pine Script™ Release notes',
docs: 'https://docs.rsshub.app/routes/program-update#tradingview-pine-script%E2%84%A2-release-notes',
source: ['/pine-script-docs/en/:version/Release_notes.html'],
target: '/tradingview/pine/:version',
},
],
},
};
1 change: 1 addition & 0 deletions lib/v2/tradingview/router.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = function (router) {
router.get('/blog/:category*', require('./blog'));
router.get('/desktop', require('./desktop'));
router.get('/pine/:version?', require('./pine'));
};
7 changes: 7 additions & 0 deletions website/docs/routes/program-update.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,13 @@ Logseq 开发团队已经放弃了 [旧网站](https://logseq.com/blog)。

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

### Pine Script™ Release notes {#tradingview-pine-script%E2%84%A2-release-notes}

<Route author="nczitzk" example="/tradingview/pine" path="/tradingview/pine/version?" paramsDesc={['Version, see below, `v5` by default']} radar="1">
| v5 | v4 |
| -- | -- |
</Route>

## Typora {#typora}

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