feat(route): Add Ash Maurya's blog (#8344)
Co-authored-by: Tony <TonyRL@users.noreply.github.com>
This commit is contained in:
parent
001ec07737
commit
6ab36103ba
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/ash-maurya': ['james-tindal'],
|
||||
};
|
||||
|
|
@ -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',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/', require('./index'));
|
||||
};
|
||||
Loading…
Reference in New Issue