From fbabfc2a216b996992123c2c255ea0a6c97d3c7c Mon Sep 17 00:00:00 2001
From: CpDong <93034081+Bubbu0129@users.noreply.github.com>
Date: Tue, 7 Feb 2023 23:11:35 +0800
Subject: [PATCH] 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
---------
---
docs/en/new-media.md | 12 ++++
docs/new-media.md | 12 ++++
lib/v2/mclaren/index.js | 95 +++++++++++++++++++++++++++++++
lib/v2/mclaren/maintainer.js | 3 +
lib/v2/mclaren/radar.js | 26 +++++++++
lib/v2/mclaren/router.js | 3 +
lib/v2/mclaren/templates/desc.art | 6 ++
7 files changed, 157 insertions(+)
create mode 100644 lib/v2/mclaren/index.js
create mode 100644 lib/v2/mclaren/maintainer.js
create mode 100644 lib/v2/mclaren/radar.js
create mode 100644 lib/v2/mclaren/router.js
create mode 100644 lib/v2/mclaren/templates/desc.art
diff --git a/docs/en/new-media.md b/docs/en/new-media.md
index c5aed9db18..afade523a5 100644
--- a/docs/en/new-media.md
+++ b/docs/en/new-media.md
@@ -492,6 +492,18 @@ Edition
+## McLaren Racing
+
+### Articles
+
+
+
+| All Media | Article | Report | Gallery | Video | Blog | Photo Essay |
+| --------- | ------- | ------ | ------- | ----- | ---- | ----------- |
+| all | article | report | gallery | video | blog | photo\_essay |
+
+
+
## Mirror
### User
diff --git a/docs/new-media.md b/docs/new-media.md
index c0d4eafe36..877e6a1ac4 100644
--- a/docs/new-media.md
+++ b/docs/new-media.md
@@ -891,6 +891,18 @@ IPFS 网关有可能失效,那时候换成其他网关。
+## 迈凯伦赛车
+
+### 文章
+
+
+
+| 所有媒体 | 文章 | 报道 | 图库 | 视频 | 博客 | 图文 (Photo Essay) |
+| -------- | ---- | ---- | ---- | ---- | ---- | ------------------ |
+| all | article | report | gallery | video | blog | photo\_essay |
+
+
+
## Mirror
### User
diff --git a/lib/v2/mclaren/index.js b/lib/v2/mclaren/index.js
new file mode 100644
index 0000000000..887401e2ca
--- /dev/null
+++ b/lib/v2/mclaren/index.js
@@ -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,
+ };
+};
diff --git a/lib/v2/mclaren/maintainer.js b/lib/v2/mclaren/maintainer.js
new file mode 100644
index 0000000000..609f6e29d5
--- /dev/null
+++ b/lib/v2/mclaren/maintainer.js
@@ -0,0 +1,3 @@
+module.exports = {
+ '/:lang/:category?': ['Bubbu0129'],
+};
diff --git a/lib/v2/mclaren/radar.js b/lib/v2/mclaren/radar.js
new file mode 100644
index 0000000000..df373124d2
--- /dev/null
+++ b/lib/v2/mclaren/radar.js
@@ -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'
+ },
+ ],
+ },
+};
diff --git a/lib/v2/mclaren/router.js b/lib/v2/mclaren/router.js
new file mode 100644
index 0000000000..d6a6c33b2e
--- /dev/null
+++ b/lib/v2/mclaren/router.js
@@ -0,0 +1,3 @@
+module.exports = function (router) {
+ router.get('/:lang/:category?', require('./index'));
+};
diff --git a/lib/v2/mclaren/templates/desc.art b/lib/v2/mclaren/templates/desc.art
new file mode 100644
index 0000000000..5c8440998d
--- /dev/null
+++ b/lib/v2/mclaren/templates/desc.art
@@ -0,0 +1,6 @@
+
{{ desc }}
+
+{{ if videoId }}
+
+{{ /if }}
+{{@ content }}