feat(route): add TradingView Blog (#10324)
* feat(route): add TradingView Blog * fix: limit the concurrency with tiny-async-pool
This commit is contained in:
@@ -460,6 +460,39 @@ Refer to [#minecraft](/en/game.html#minecraft)
|
||||
|
||||
<RouteEn author="nczitzk" example="/totalcommander/whatsnew" path="/totalcommander/whatsnew"/>
|
||||
|
||||
## TradingView
|
||||
|
||||
### Blog
|
||||
|
||||
<RouteEn author="nczitzk" example="/tradingview/blog/en" path="/tradingview/blog/:language?" :paramsDesc="['Language, see below, `en` as English by default']">
|
||||
|
||||
Language
|
||||
|
||||
| Id | Language |
|
||||
| -- | ------------------- |
|
||||
| en | English |
|
||||
| ru | Русский |
|
||||
| ja | 日本語 |
|
||||
| es | Español |
|
||||
| tr | Türkçe |
|
||||
| ko | 한국어 |
|
||||
| it | Italiano |
|
||||
| pt | Português do Brasil |
|
||||
| de | Deutsch |
|
||||
| fr | Français |
|
||||
| pl | Polski |
|
||||
| id | Bahasa Indonesia |
|
||||
| my | Bahasa Malaysia |
|
||||
| tw | 繁體 |
|
||||
| cn | 简体 |
|
||||
| vi | Tiếng Việt |
|
||||
| th | ภาษาไทย |
|
||||
| sv | Svenska |
|
||||
| ar | العربية |
|
||||
| il | Hebrew |
|
||||
|
||||
</RouteEn>
|
||||
|
||||
## Typora
|
||||
|
||||
### Changelog
|
||||
|
||||
@@ -543,6 +543,39 @@ pageClass: routes
|
||||
|
||||
<Route author="nczitzk" example="/totalcommander/whatsnew" path="/totalcommander/whatsnew"/>
|
||||
|
||||
## TradingView
|
||||
|
||||
### Blog
|
||||
|
||||
<Route author="nczitzk" example="/tradingview/blog/en" path="/tradingview/blog/:language?" :paramsDesc="['语言,见下表,默认为 en 即英语']">
|
||||
|
||||
语言
|
||||
|
||||
| 编号 | 语言 |
|
||||
| -- | ------------------- |
|
||||
| en | English |
|
||||
| ru | Русский |
|
||||
| ja | 日本語 |
|
||||
| es | Español |
|
||||
| tr | Türkçe |
|
||||
| ko | 한국어 |
|
||||
| it | Italiano |
|
||||
| pt | Português do Brasil |
|
||||
| de | Deutsch |
|
||||
| fr | Français |
|
||||
| pl | Polski |
|
||||
| id | Bahasa Indonesia |
|
||||
| my | Bahasa Malaysia |
|
||||
| tw | 繁體 |
|
||||
| cn | 简体 |
|
||||
| vi | Tiếng Việt |
|
||||
| th | ภาษาไทย |
|
||||
| sv | Svenska |
|
||||
| ar | العربية |
|
||||
| il | Hebrew |
|
||||
|
||||
</Route>
|
||||
|
||||
## Typora
|
||||
|
||||
### Changelog
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const asyncPool = require('tiny-async-pool');
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const language = ctx.params.language ?? 'en';
|
||||
|
||||
const rootUrl = 'https://www.tradingview.com';
|
||||
const currentUrl = `${rootUrl}/blog/${language}`;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const list = $('.articles-grid-item a[rel="bookmark"]')
|
||||
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 20)
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
|
||||
return {
|
||||
title: item.find('.title').text(),
|
||||
link: item.attr('href'),
|
||||
pubDate: parseDate(item.find('.date').text(), 'MMMM D, YYYY'),
|
||||
};
|
||||
});
|
||||
|
||||
const items = [];
|
||||
for await (const item of asyncPool(3, list, (item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.description = art(path.join(__dirname, 'templates/description.art'), {
|
||||
image: content('.single-img img').attr('src'),
|
||||
description: content('.entry-content').html(),
|
||||
});
|
||||
|
||||
return item;
|
||||
})
|
||||
)) {
|
||||
items.push(item);
|
||||
}
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/blog/:language?': ['nczitzk'],
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
module.exports = {
|
||||
'tradingview.com': {
|
||||
_name: 'TradingView',
|
||||
'.': [
|
||||
{
|
||||
title: 'Blog',
|
||||
docs: 'https://docs.rsshub.app/program-update.html#tradingview-blog',
|
||||
source: ['/blog/:language', '/'],
|
||||
target: '/tradingview/blog',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = function (router) {
|
||||
router.get('/blog/:language?', require('./blog'));
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
{{ if image }}
|
||||
<img src="{{ image }}">
|
||||
{{ /if }}
|
||||
{{@ description }}
|
||||
Reference in New Issue
Block a user