From b31adca78ee92049c8c0c01a5e5845ffaab2a362 Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Fri, 19 Jan 2024 01:06:41 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20TradingView=20Pine=20Scrip?= =?UTF-8?q?t=E2=84=A2=20Release=20notes=20(#14279)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/v2/tradingview/pine.js | 54 ++++++++++++++++++++++++++ lib/v2/tradingview/radar.js | 6 +++ lib/v2/tradingview/router.js | 1 + website/docs/routes/program-update.mdx | 7 ++++ 4 files changed, 68 insertions(+) create mode 100644 lib/v2/tradingview/pine.js diff --git a/lib/v2/tradingview/pine.js b/lib/v2/tradingview/pine.js new file mode 100644 index 000000000..5fcaae20c --- /dev/null +++ b/lib/v2/tradingview/pine.js @@ -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; + + 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, + }; +}; diff --git a/lib/v2/tradingview/radar.js b/lib/v2/tradingview/radar.js index 04884af51..084bcfec3 100644 --- a/lib/v2/tradingview/radar.js +++ b/lib/v2/tradingview/radar.js @@ -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', + }, ], }, }; diff --git a/lib/v2/tradingview/router.js b/lib/v2/tradingview/router.js index a985e2dcc..255bf16d7 100644 --- a/lib/v2/tradingview/router.js +++ b/lib/v2/tradingview/router.js @@ -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')); }; diff --git a/website/docs/routes/program-update.mdx b/website/docs/routes/program-update.mdx index a03328077..c0c2f83f8 100644 --- a/website/docs/routes/program-update.mdx +++ b/website/docs/routes/program-update.mdx @@ -620,6 +620,13 @@ Logseq 开发团队已经放弃了 [旧网站](https://logseq.com/blog)。 +### Pine Script™ Release notes {#tradingview-pine-script%E2%84%A2-release-notes} + + + | v5 | v4 | + | -- | -- | + + ## Typora {#typora} ### Changelog {#typora-changelog}