feat(route): Add Ash Maurya's blog (#8344)

Co-authored-by: Tony <TonyRL@users.noreply.github.com>
This commit is contained in:
James Tindal 2021-11-27 08:34:37 +00:00 committed by GitHub
parent 001ec07737
commit 6ab36103ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 79 additions and 0 deletions

View File

@ -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

View File

@ -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,
};
};

View File

@ -0,0 +1,3 @@
module.exports = {
'/ash-maurya': ['james-tindal'],
};

View File

@ -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',
},
],
},
};

View File

@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/', require('./index'));
};