feat(routes): CSDN 博客 (#10447)

* feat(routes): CSDN Blog

* fix(docs): add CSDN Blog paramsDesc
This commit is contained in:
Jerry K Jia 2022-08-16 20:30:22 -04:00 committed by GitHub
parent 106341f4e6
commit 5f9018c3df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 72 additions and 0 deletions

View File

@ -349,3 +349,10 @@ username 为博主用户名,而非`xxx.hashnode.dev`中`xxx`所代表的 blog
:::
</Route>
## CSDN
### 用户博客
<Route author="Jkker" example="/csdn/blog/csdngeeknews" path="/csdn/blog/:user" radar="1" :paramsDesc="['`user` 为 CSDN 用户名,可以在主页 url 中找到']" />

View File

@ -95,3 +95,10 @@ Limit the number of entries to be retrieved by adding `?limit=x` to the end of t
### Entry
<RouteEn author="nczitzk" example="/yuzu-emu/entry" path="/yuzu-emu/entry" />
## CSDN
### User Feed
<RouteEn author="Jkker" example="/csdn/blog/csdngeeknews" path="/csdn/blog/:user" radar="1" :paramsDesc="['`user` is the username of a CSDN blog which can be found in the url of the home page']" />

39
lib/v2/csdn/blog.js Normal file
View File

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

View File

@ -0,0 +1,3 @@
module.exports = {
'/blog': ['Jkker'],
};

13
lib/v2/csdn/radar.js Normal file
View File

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

3
lib/v2/csdn/router.js Normal file
View File

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