diff --git a/docs/programming.md b/docs/programming.md index 35c89443a7..f3a85ee509 100644 --- a/docs/programming.md +++ b/docs/programming.md @@ -24,6 +24,12 @@ pageClass: routes +## deeplearning.ai + +### TheBatch 周报 + + + ## Dockone ### 周报 diff --git a/lib/router.js b/lib/router.js index 2211360961..c6ae0333d4 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2675,6 +2675,9 @@ router.get('/qingting/channel/:id', require('./routes/qingting/channel')); // 金色财经 router.get('/jinse/lives', require('./routes/jinse/lives')); +// deeplearning.ai +router.get('/deeplearningai/thebatch', require('./routes/deeplearningai/thebatch')); + // Fate Grand Order router.get('/fgo/news', require('./routes/fgo/news')); diff --git a/lib/routes/deeplearningai/thebatch.js b/lib/routes/deeplearningai/thebatch.js new file mode 100644 index 0000000000..1720dd53ad --- /dev/null +++ b/lib/routes/deeplearningai/thebatch.js @@ -0,0 +1,30 @@ +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( + async (item) => + await 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; + }) + ) + ), + }; +};