feat(routes): CSDN 博客 (#10447)
* feat(routes): CSDN Blog * fix(docs): add CSDN Blog paramsDesc
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const rssParser = require('@/utils/rss-parser');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const user = ctx.params.user;
|
||||
|
||||
const rootUrl = 'https://blog.csdn.net';
|
||||
const blogUrl = `${rootUrl}/${user}`;
|
||||
const rssUrl = blogUrl + '/rss/list';
|
||||
|
||||
const feed = await rssParser.parseURL(rssUrl);
|
||||
|
||||
const items = await Promise.all(
|
||||
feed.items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const description = $('#content_views').html();
|
||||
|
||||
return {
|
||||
...item,
|
||||
description,
|
||||
};
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
...feed,
|
||||
title: `${feed.title} - CSDN博客`,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/blog': ['Jkker'],
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
module.exports = {
|
||||
'csdn.net': {
|
||||
_name: 'CSDN',
|
||||
blog: [
|
||||
{
|
||||
title: '博客',
|
||||
docs: 'https://docs.rsshub.app/blog.html#csdn',
|
||||
source: ['/:user'],
|
||||
target: '/csdn/blog/:user',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = function (router) {
|
||||
router.get('/blog/:user', require('./blog'));
|
||||
};
|
||||
Reference in New Issue
Block a user