feat(route): Add "Mclaren Racing" (#11783)

* Add route "Mclaren Racing"

* Add English documentation for "Mclaren Racing"

* Add radar.js for "Mclaren Racing"

* Lint index.js of "Mclaren Racing"

* Add more categories to "Mclaren Racing"

* Update lib/v2/mclaren/radar.js

* Update lib/v2/mclaren/radar.js

* Update lib/v2/mclaren/radar.js

* Update lib/v2/mclaren/radar.js

* Update lib/v2/mclaren/index.js

* Update lib/v2/mclaren/radar.js

* Update lib/v2/mclaren/radar.js

* Update lib/v2/mclaren/radar.js

* Update docs/new-media.md

* Update docs/new-media.md

* Update docs/new-media.md

* Update docs/en/new-media.md

* Update docs/en/new-media.md

* Update docs/en/new-media.md

* Fix everything!

* Fix radar.js

* Fix lint issues

* Fix deleting useful content

* Remove duplicated comments

---------
This commit is contained in:
CpDong
2023-02-07 23:11:35 +08:00
committed by GitHub
parent 53d7503038
commit fbabfc2a21
7 changed files with 157 additions and 0 deletions
+12
View File
@@ -492,6 +492,18 @@ Edition
<RouteEn author="Cerebrater xosdy" example="/matters/author/az" path="/matters/author/:uid" :paramsDesc="['Author id, can be found at author\'s homepage url']" radar="1" rssbud="1"/>
## McLaren Racing
### Articles
<RouteEn author="Bubbu0129" example="/mclaren/en/all" path="/mclaren/:lang/:category?" :paramsDesc="['Supports English(en), Simplified Chinese(zh), and Spanish(es).', 'Default to exporting all media (all); See the table below for details']" radar="1" rssbud="1">
| All Media | Article | Report | Gallery | Video | Blog | Photo Essay |
| --------- | ------- | ------ | ------- | ----- | ---- | ----------- |
| all | article | report | gallery | video | blog | photo\_essay |
</RouteEn>
## Mirror
### User
+12
View File
@@ -891,6 +891,18 @@ IPFS 网关有可能失效,那时候换成其他网关。
<Route author="Cerebrater xosdy" example="/matters/author/az" path="/matters/author/:uid" :paramsDesc="['作者 id,可在作者主页的 URL 找到']" radar="1" rssbud="1"/>
## 迈凯伦赛车
### 文章
<Route author="Bubbu0129" example="/mclaren/en/all" path="/mclaren/:lang/:category?" :paramsDesc="['支持英语(en)、简体中文(zh)、与西班牙语(es)。', '默认输出所有媒体(all);见下表:']" radar="1" rssbud="1">
| 所有媒体 | 文章 | 报道 | 图库 | 视频 | 博客 | 图文 (Photo Essay) |
| -------- | ---- | ---- | ---- | ---- | ---- | ------------------ |
| all | article | report | gallery | video | blog | photo\_essay |
</Route>
## Mirror
### User
+95
View File
@@ -0,0 +1,95 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const path = require('path');
const { art } = require('@/utils/render');
module.exports = async (ctx) => {
let baseUrl, apiUrl;
let title, description;
let lang = ctx.params.lang;
switch (lang) {
case 'en':
baseUrl = 'https://www.mclaren.com';
title = 'McLaren Racing – Official Website';
description = 'Latest news and insight from McLaren Racing. Team and driver updates, videos and McLaren Formula 1 LIVE commentary.';
lang = 'en-UK';
break;
case 'zh':
baseUrl = 'https://cn.mclaren.com';
title = '迈凯伦赛车 — 官方网站';
description = '来自迈凯伦一级方程式车队的最新消息。 查看车队和车手近况、视频以及比赛中的迈凯伦实况评论和实时数据。';
lang = 'zh-CN';
break;
case 'es':
baseUrl = 'https://es.mclaren.com';
title = 'McLaren Racing - Sitio web oficial';
description = 'Consulta las últimas noticias del equipo de Fórmula 1 McLaren. Incluye información sobre el equipo, las últimas actualizaciones de los pilotos y McLaren LIVE, una aplicación con la que podrás seguir los comentarios en directo.';
lang = 'es-ES';
break;
default:
throw Error(`Language '${lang}' is not supported.`);
};
const { category = 'all' } = ctx.params;
const categoryArr = ['all', 'article', 'report', 'gallery', 'video', 'blog', 'photo_essay'];
if (!categoryArr.includes(category)) {
throw Error(`Category '${category}' is not supported.`);
};
const link = baseUrl + '/racing/articles/';
apiUrl = baseUrl + '/racing/api/grid-search/?count=30&offset=0&type=';
// count: number of requested entries; default to 16, up to 30.
// offset: default to 0.
if (category !== 'all') {
apiUrl += category;
}
const response = await got(apiUrl);
const html = response.data.html;
const $ = cheerio.load(html);
const list = $('li')
.toArray()
.map((item) => {
item = $(item);
const thumbnailUrl = item.find('div.start-grid-content__img').attr('style').slice(22, -2);
return {
link: baseUrl + item.find('a.start-grid-content__link').attr('href'),
thumbnailUrl, // Pass the thumbnail image
};
});
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const itemRep = await got(item.link);
const $ = cheerio.load(itemRep.data);
$('.livestream--wrapper').last().remove();
item.title = $('meta[property="og:title"]').attr('content').slice(17);
item.pubDate = Date.parse($('time[datetime]').first().attr('datetime'));
const artParams = {
desc: $('meta[property="og:description"]').attr('content'),
heroUrl: $('meta[property="og:image"]').attr('content'),
videoId: $('a[data-video-id]').attr('data-video-id'),
};
$('.meta--hold, .show-for-small').remove();
artParams.content = $('div.article-body').html();
item.description = art(path.join(__dirname, 'templates/desc.art'), artParams);
item.media = {
thumbnail: {
url: item.thumbnailUrl,
},
};
return item;
})
)
);
ctx.state.data = {
language: lang,
title,
description,
link,
item: items,
};
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/:lang/:category?': ['Bubbu0129'],
};
+26
View File
@@ -0,0 +1,26 @@
module.exports = {
'mclaren.com': {
_name: 'Mclaren Racing',
www: [{
title: 'Mclaren Racing',
docs: 'https://docs.rsshub.app/new-media.html#mai-kai-lun-sai-che',
source: '/racing/articles/',
target: '/mclaren/en/all'
},
],
cn: [{
title: '迈凯伦赛车',
docs: 'https://docs.rsshub.app/new-media.html#mai-kai-lun-sai-che',
source: '/racing/articles/',
target: '/mclaren/zh/all'
},
],
es: [{
title: 'Mclaren Racing',
docs: 'https://docs.rsshub.app/new-media.html#mai-kai-lun-sai-che',
source: '/racing/articles/',
target: '/mclaren/es/all'
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/:lang/:category?', require('./index'));
};
+6
View File
@@ -0,0 +1,6 @@
<p>{{ desc }}</p><br>
<center><img src="{{ heroUrl }}"></center><br>
{{ if videoId }}
<center><iframe id="ytplayer" type="text/html" width="640" height="360" src="https://www.youtube-nocookie.com/embed/{{ videoId }}" frameborder="0" allowfullscreen></iframe></center><br>
{{ /if }}
{{@ content }}