mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-04 19:59:54 +08:00
feat(route): 添加路由 FX-Markets.com (#9801)
* Add a new router for fx-markets.com * Correct link to doc in radar definition * Add en docs for fx-markets.com * Update docs section title as suggested * Use parseDate instead of date; remove unnecessary async as suggested
This commit is contained in:
@@ -16,6 +16,16 @@ pageClass: routes
|
|||||||
|
|
||||||
<RouteEn author="HenryQW" example="/finviz/news/AAPL" path="/finviz/news/:ticker" :paramsDesc="['The stock ticker']"/>
|
<RouteEn author="HenryQW" example="/finviz/news/AAPL" path="/finviz/news/:ticker" :paramsDesc="['The stock ticker']"/>
|
||||||
|
|
||||||
|
## FX Markets
|
||||||
|
|
||||||
|
<RouteEn author="mikkkee" example="/fx-markets/trading" path="/fx-markets/:channel" :paramsDesc="['channel, can be found in the navi bar links at the home page']">
|
||||||
|
|
||||||
|
| Trading | Infrastructure | Tech and Data | Regulation |
|
||||||
|
| ------- | -------------- | ------------- | ---------- |
|
||||||
|
| trading | infrastructure | tech-and-data | regulation |
|
||||||
|
|
||||||
|
</RouteEn>
|
||||||
|
|
||||||
## TokenInsight
|
## TokenInsight
|
||||||
|
|
||||||
### Blogs
|
### Blogs
|
||||||
|
|||||||
@@ -44,6 +44,16 @@ pageClass: routes
|
|||||||
|
|
||||||
<Route author="HenryQW" example="/finviz/news/AAPL" path="/finviz/news/:ticker" :paramsDesc="['股票代码']"/>
|
<Route author="HenryQW" example="/finviz/news/AAPL" path="/finviz/news/:ticker" :paramsDesc="['股票代码']"/>
|
||||||
|
|
||||||
|
## FX Markets
|
||||||
|
|
||||||
|
<Route author="mikkkee" example="/fx-markets/trading" path="/fx-markets/:channel" :paramsDesc="['分类代码,可在首页导航栏的目标网址 URL 中找到']">
|
||||||
|
|
||||||
|
| Trading | Infrastructure | Tech and Data | Regulation |
|
||||||
|
| ------- | -------------- | ------------- | ---------- |
|
||||||
|
| trading | infrastructure | tech-and-data | regulation |
|
||||||
|
|
||||||
|
</Route>
|
||||||
|
|
||||||
## TokenInsight
|
## TokenInsight
|
||||||
|
|
||||||
### 博客
|
### 博客
|
||||||
|
|||||||
56
lib/v2/fx-markets/channel.js
Normal file
56
lib/v2/fx-markets/channel.js
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
const cheerio = require('cheerio');
|
||||||
|
const got = require('@/utils/got');
|
||||||
|
const { parseDate } = require('@/utils/parse-date');
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const channel = ctx.params.channel;
|
||||||
|
const link = `https://www.fx-markets.com/${channel}`;
|
||||||
|
const html = (await got(link)).data;
|
||||||
|
const $ = cheerio.load(html);
|
||||||
|
const pageTitle = $('header.select-header > h1').text();
|
||||||
|
const title = `FX-Markets ${pageTitle}`;
|
||||||
|
|
||||||
|
const items = $('div#listings').children();
|
||||||
|
const articles = items
|
||||||
|
.map((i, el) => {
|
||||||
|
const $el = $(el);
|
||||||
|
const $titleEl = $el.find('h5 > a');
|
||||||
|
const articleURL = `https://www.fx-markets.com${$titleEl.attr('href')}`;
|
||||||
|
const articleTitle = $titleEl.attr('title');
|
||||||
|
return {
|
||||||
|
title: articleTitle,
|
||||||
|
link: articleURL,
|
||||||
|
pubDate: parseDate($el.find('time').text()),
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.get();
|
||||||
|
|
||||||
|
const result = await Promise.all(
|
||||||
|
articles.map((item) =>
|
||||||
|
ctx.cache.tryGet(item.link, async () => {
|
||||||
|
const res = await got(item.link);
|
||||||
|
const doc = cheerio.load(res.data);
|
||||||
|
// This script holds publish datetime info {"datePublished": "2022-05-12T08:45:04+01:00"}
|
||||||
|
const dateScript = doc('script[type="application/ld+json"]').get()[0].children[0].data;
|
||||||
|
const re = /"datePublished": "(?<dateTimePub>.*)"/;
|
||||||
|
const dateStr = re.exec(dateScript).groups.dateTimePub;
|
||||||
|
const pubDateTime = parseDate(dateStr, 'YYYY-MM-DDTHH:mm:ssZ');
|
||||||
|
// Exclude hidden print message
|
||||||
|
item.description = doc('div.article-page-body-content:not(.print-access-info)').html();
|
||||||
|
return {
|
||||||
|
title: item.title,
|
||||||
|
link: item.link,
|
||||||
|
description: item.description,
|
||||||
|
// if we fail to get accurate publish date time, show date only from article link on index page.
|
||||||
|
pubDate: pubDateTime ? pubDateTime : item.pubDate,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title,
|
||||||
|
link,
|
||||||
|
item: result,
|
||||||
|
};
|
||||||
|
};
|
||||||
3
lib/v2/fx-markets/maintainer.js
Normal file
3
lib/v2/fx-markets/maintainer.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = {
|
||||||
|
'/fx-markets/:channel': ['mikkkee'],
|
||||||
|
};
|
||||||
31
lib/v2/fx-markets/radar.js
Normal file
31
lib/v2/fx-markets/radar.js
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
module.exports = {
|
||||||
|
'fx-markets.com': {
|
||||||
|
_name: 'FX-Markets',
|
||||||
|
'.': [
|
||||||
|
{
|
||||||
|
title: 'Trading',
|
||||||
|
docs: 'https://docs.rsshub.app/finance.html#fx-markets',
|
||||||
|
source: '/trading',
|
||||||
|
target: '/fx-markets/trading',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Infrastructure',
|
||||||
|
docs: 'https://docs.rsshub.app/finance.html#fx-markets',
|
||||||
|
source: '/infrastructure',
|
||||||
|
target: '/fx-markets/infrastructure',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Tech and Data',
|
||||||
|
docs: 'https://docs.rsshub.app/finance.html#fx-markets',
|
||||||
|
source: '/tech-and-data',
|
||||||
|
target: '/fx-markets/tech-and-data',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Regulation',
|
||||||
|
docs: 'https://docs.rsshub.app/finance.html#fx-markets',
|
||||||
|
source: '/regulation',
|
||||||
|
target: '/fx-markets/regulation',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
3
lib/v2/fx-markets/router.js
Normal file
3
lib/v2/fx-markets/router.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = (router) => {
|
||||||
|
router.get('/:channel', require('./channel'));
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user