fix(route/deeplearning): The batch from deeplearning.ai (#14066)
* fix(the-batch): The batch from deeplearning.ai * refactor: migrate to v2 ---------
This commit is contained in:
+1
-1
@@ -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'));
|
||||
|
||||
@@ -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;
|
||||
})
|
||||
)
|
||||
),
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/thebatch': ['nczitzk', 'juvenn'],
|
||||
};
|
||||
@@ -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',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = (router) => {
|
||||
router.get('/thebatch', require('./thebatch'));
|
||||
};
|
||||
@@ -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(/<script id="__NEXT_DATA__" type="application\/json">(.*)<\/script>/)[1];
|
||||
const nextBuildId = JSON.parse(nextJs).buildId;
|
||||
|
||||
const listing = await got({
|
||||
method: 'get',
|
||||
url: `https://www.deeplearning.ai/_next/data/${nextBuildId}/the-batch.json`,
|
||||
});
|
||||
|
||||
const items = listing.data.pageProps.posts.map((item) => ({
|
||||
title: item.title,
|
||||
link: `https://www.deeplearning.ai/the-batch/${item.slug}`,
|
||||
jsonUrl: `https://www.deeplearning.ai/_next/data/${nextBuildId}/the-batch/${item.slug}.json`,
|
||||
pubDate: new Date(item.published_at).toUTCString(),
|
||||
}));
|
||||
|
||||
ctx.state.data = {
|
||||
title: `The Batch - a new weekly newsletter from deeplearning.ai`,
|
||||
link: `https://www.deeplearning.ai/the-batch/`,
|
||||
item: await Promise.all(
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const resp = await got({ method: 'get', url: item.jsonUrl });
|
||||
item.description = resp.data.pageProps.cmsData.post.html;
|
||||
return item;
|
||||
})
|
||||
)
|
||||
),
|
||||
};
|
||||
};
|
||||
@@ -202,7 +202,7 @@
|
||||
|
||||
### TheBatch 周报 {#deeplearning-ai-thebatch-zhou-bao}
|
||||
|
||||
<Route author="nczitzk" example="/deeplearningai/thebatch" path="/deeplearningai/thebatch" notOperational="1" />
|
||||
<Route author="nczitzk juvenn" example="/deeplearning/thebatch" path="/deeplearning/thebatch" radar="1" />
|
||||
|
||||
## Distill {#distill}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user