diff --git a/docs/en/blog.md b/docs/en/blog.md index 0053952bde8f39..8ee31450352e01 100644 --- a/docs/en/blog.md +++ b/docs/en/blog.md @@ -26,6 +26,12 @@ pageClass: routes +## Love the Problem + +### Ash Maurya's blog + + + ## Paul Graham ### Essays diff --git a/lib/v2/ash-maurya/index.js b/lib/v2/ash-maurya/index.js new file mode 100644 index 00000000000000..067c5569933cd1 --- /dev/null +++ b/lib/v2/ash-maurya/index.js @@ -0,0 +1,54 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +async function getList(rootUrl) { + const pages = []; + let next = rootUrl; + do { + // eslint-disable-next-line no-await-in-loop + const response = await got({ method: 'get', url: next }); + const $ = cheerio.load(response.data); + pages.push( + $('article').map((_, item) => ({ + title: $(item).find('.post-card-title').text(), + link: rootUrl + $(item).find('.post-card-content-link').attr('href'), + })) + ); + next = $('link[rel=next]').attr('href'); + } while (next); + return pages.reduce((acc, page) => cheerio.merge(acc, page)).get(); +} + +module.exports = async (ctx) => { + const rootUrl = 'https://blog.leanstack.com/'; + + const list = await getList(rootUrl); + + const items = ( + await Promise.all( + list.map(({ link, title }) => + ctx.cache.tryGet(link, () => + got({ method: 'get', url: link }) + .then(({ data }) => { + const content = cheerio.load(data); + + return { + link, + title, + author: 'Ash Maurya', + description: (content('.post-full-image').html() ?? '') + content('.post-content').html(), + pubDate: content('meta[property="article:published_time"]').attr('content'), + }; + }) + .catch(() => null) + ) + ) + ) + ).filter((x) => x !== null); + + ctx.state.data = { + title: "Ash Maurya's blog", + link: rootUrl, + item: items, + }; +}; diff --git a/lib/v2/ash-maurya/maintainer.js b/lib/v2/ash-maurya/maintainer.js new file mode 100644 index 00000000000000..b41c9d538ed37a --- /dev/null +++ b/lib/v2/ash-maurya/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/ash-maurya': ['james-tindal'], +}; diff --git a/lib/v2/ash-maurya/radar.js b/lib/v2/ash-maurya/radar.js new file mode 100644 index 00000000000000..f6ddc3a7734230 --- /dev/null +++ b/lib/v2/ash-maurya/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'blog.leanstack.com': { + _name: "Ash Maurya's blog", + '.': [ + { + title: "Ash Maurya's blog", + docs: 'https://docs.rsshub.app/en/blog.html#ash-maurya', + source: ['/'], + target: '/ash-maurya', + }, + ], + }, +}; diff --git a/lib/v2/ash-maurya/router.js b/lib/v2/ash-maurya/router.js new file mode 100644 index 00000000000000..20c52b09d72938 --- /dev/null +++ b/lib/v2/ash-maurya/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/', require('./index')); +};