-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add TradingView Pine Script™ Release notes (#14279)
- Loading branch information
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
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, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters