From 376ebf4bc46db3e4d42bf4997fb60e7e07fc93c5 Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Sun, 14 Jan 2024 16:02:07 +0800 Subject: [PATCH] feat(route): add TradingView Desktop releases and release notes (#14234) --- lib/v2/tradingview/desktop.js | 61 ++++++++++++++++++++++++++ lib/v2/tradingview/maintainer.js | 1 + lib/v2/tradingview/radar.js | 6 +++ lib/v2/tradingview/router.js | 1 + website/docs/routes/program-update.mdx | 4 ++ 5 files changed, 73 insertions(+) create mode 100644 lib/v2/tradingview/desktop.js diff --git a/lib/v2/tradingview/desktop.js b/lib/v2/tradingview/desktop.js new file mode 100644 index 00000000000000..e894fae40428a4 --- /dev/null +++ b/lib/v2/tradingview/desktop.js @@ -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(), + }; +}; diff --git a/lib/v2/tradingview/maintainer.js b/lib/v2/tradingview/maintainer.js index cb9d37b3a3a949..10e854fa3281b6 100644 --- a/lib/v2/tradingview/maintainer.js +++ b/lib/v2/tradingview/maintainer.js @@ -1,3 +1,4 @@ module.exports = { '/blog/:language?/category/:category?': ['nczitzk'], + '/desktop': ['nczitzk'], }; diff --git a/lib/v2/tradingview/radar.js b/lib/v2/tradingview/radar.js index 642caa3f60af72..04884af51e58a4 100644 --- a/lib/v2/tradingview/radar.js +++ b/lib/v2/tradingview/radar.js @@ -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', + }, ], }, }; diff --git a/lib/v2/tradingview/router.js b/lib/v2/tradingview/router.js index 98bb22bf2c0d0a..a985e2dcc14ac0 100644 --- a/lib/v2/tradingview/router.js +++ b/lib/v2/tradingview/router.js @@ -1,3 +1,4 @@ module.exports = function (router) { router.get('/blog/:category*', require('./blog')); + router.get('/desktop', require('./desktop')); }; diff --git a/website/docs/routes/program-update.mdx b/website/docs/routes/program-update.mdx index ccf012212ff8e0..a03328077f5e5f 100644 --- a/website/docs/routes/program-update.mdx +++ b/website/docs/routes/program-update.mdx @@ -616,6 +616,10 @@ Logseq 开发团队已经放弃了 [旧网站](https://logseq.com/blog)。 | [Widgets](https://www.tradingview.com/blog/en/category/widgets/) | category/widgets | +### Desktop releases and release notes {#tradingview-desktop-releases-and-release-notes} + + + ## Typora {#typora} ### Changelog {#typora-changelog}