From 5aef90d9f4142394b9be90e24dec521c0c8cdb6b Mon Sep 17 00:00:00 2001 From: Juvenn Woo Date: Mon, 18 Dec 2023 01:56:10 +0800 Subject: [PATCH] fix(route/deeplearning): The batch from deeplearning.ai (#14066) * fix(the-batch): The batch from deeplearning.ai * refactor: migrate to v2 --------- --- lib/router.js | 2 +- lib/routes/deeplearningai/thebatch.js | 29 --------------------- lib/v2/deeplearning/maintainer.js | 3 +++ lib/v2/deeplearning/radar.js | 13 ++++++++++ lib/v2/deeplearning/router.js | 3 +++ lib/v2/deeplearning/thebatch.js | 36 +++++++++++++++++++++++++++ website/docs/routes/programming.mdx | 2 +- 7 files changed, 57 insertions(+), 31 deletions(-) delete mode 100644 lib/routes/deeplearningai/thebatch.js create mode 100644 lib/v2/deeplearning/maintainer.js create mode 100644 lib/v2/deeplearning/radar.js create mode 100644 lib/v2/deeplearning/router.js create mode 100644 lib/v2/deeplearning/thebatch.js diff --git a/lib/router.js b/lib/router.js index 71aa9f8e7..67a41228c 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1696,7 +1696,7 @@ router.get('/jinse/timeline', lazyloadRouteHandler('./routes/jinse/timeline')); router.get('/jinse/catalogue/:caty', lazyloadRouteHandler('./routes/jinse/catalogue')); // deeplearning.ai -router.get('/deeplearningai/thebatch', lazyloadRouteHandler('./routes/deeplearningai/thebatch')); +// router.get('/deeplearningai/thebatch', lazyloadRouteHandler('./routes/deeplearningai/thebatch')); // Fate Grand Order router.get('/fgo/news', lazyloadRouteHandler('./routes/fgo/news')); diff --git a/lib/routes/deeplearningai/thebatch.js b/lib/routes/deeplearningai/thebatch.js deleted file mode 100644 index 56d4b51b6..000000000 --- a/lib/routes/deeplearningai/thebatch.js +++ /dev/null @@ -1,29 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); - -module.exports = async (ctx) => { - const response = await got({ - method: 'get', - url: `https://www.deeplearning.ai/WPCore/wp-admin/admin-ajax.php?action=hubspot_reader_blog_the_batch&offset=0&limit=5`, - }); - const list = response.data.data.map((item) => ({ - title: `${item.title} - ${item.name}`, - link: item.web_view_url, - pubDate: new Date(item.date).toUTCString(), - })); - - ctx.state.data = { - title: `The Batch - a new weekly newsletter from deeplearning.ai`, - link: `https://www.deeplearning.ai/thebatch/`, - item: await Promise.all( - list.map((item) => - ctx.cache.tryGet(item.link, async () => { - const contentResponse = await got({ method: 'get', url: item.link }); - const content = cheerio.load(contentResponse.data); - item.description = content('td[style="width: 576px;"]').parent().html(); - return item; - }) - ) - ), - }; -}; diff --git a/lib/v2/deeplearning/maintainer.js b/lib/v2/deeplearning/maintainer.js new file mode 100644 index 000000000..cd3a614dd --- /dev/null +++ b/lib/v2/deeplearning/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/thebatch': ['nczitzk', 'juvenn'], +}; diff --git a/lib/v2/deeplearning/radar.js b/lib/v2/deeplearning/radar.js new file mode 100644 index 000000000..a5de8e480 --- /dev/null +++ b/lib/v2/deeplearning/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'deeplearning.ai': { + _name: 'deeplearning.ai', + www: [ + { + title: 'TheBatch 周报', + docs: 'https://docs.rsshub.app/routes/deeplearning-ai#thebatch-zhou-bao', + source: ['/thebatch', '/'], + target: '/deeplearning/thebatch', + }, + ], + }, +}; diff --git a/lib/v2/deeplearning/router.js b/lib/v2/deeplearning/router.js new file mode 100644 index 000000000..cb6fa80a3 --- /dev/null +++ b/lib/v2/deeplearning/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/thebatch', require('./thebatch')); +}; diff --git a/lib/v2/deeplearning/thebatch.js b/lib/v2/deeplearning/thebatch.js new file mode 100644 index 000000000..28bb280dc --- /dev/null +++ b/lib/v2/deeplearning/thebatch.js @@ -0,0 +1,36 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const page = await got({ + method: 'get', + url: `https://www.deeplearning.ai/the-batch/`, + }); + const nextJs = page.data.match(/