Skip to content

Commit

Permalink
feat(route): Add Ash Maurya's blog (DIYgod#8344)
Browse files Browse the repository at this point in the history
Co-authored-by: Tony <[email protected]>
  • Loading branch information
james-tindal and TonyRL authored Nov 27, 2021
1 parent 001ec07 commit 6ab3610
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/en/blog.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ pageClass: routes

<RouteEn author="aha2mao" path="/hexo/yilia/:url" example="/hexo/yilia/cloudstone.xin" :paramsDesc="['the blog URL without the protocol (http:// and https://)']" />

## Love the Problem

### Ash Maurya's blog

<RouteEn author="james-tindal" example="/ash-maurya" path="/ash-maurya"/>

## Paul Graham

### Essays
Expand Down
54 changes: 54 additions & 0 deletions lib/v2/ash-maurya/index.js
Original file line number Diff line number Diff line change
@@ -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,
};
};
3 changes: 3 additions & 0 deletions lib/v2/ash-maurya/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/ash-maurya': ['james-tindal'],
};
13 changes: 13 additions & 0 deletions lib/v2/ash-maurya/radar.js
Original file line number Diff line number Diff line change
@@ -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',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/ash-maurya/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/', require('./index'));
};

0 comments on commit 6ab3610

Please sign in to comment.