diff --git a/docs/blog.md b/docs/blog.md index 701dede7c..2928572e5 100644 --- a/docs/blog.md +++ b/docs/blog.md @@ -349,3 +349,10 @@ username 为博主用户名,而非`xxx.hashnode.dev`中`xxx`所代表的 blog ::: + + +## CSDN + +### 用户博客 + + \ No newline at end of file diff --git a/docs/en/blog.md b/docs/en/blog.md index 143350e77..2d0686500 100644 --- a/docs/en/blog.md +++ b/docs/en/blog.md @@ -95,3 +95,10 @@ Limit the number of entries to be retrieved by adding `?limit=x` to the end of t ### Entry + + +## CSDN + +### User Feed + + \ No newline at end of file diff --git a/lib/v2/csdn/blog.js b/lib/v2/csdn/blog.js new file mode 100644 index 000000000..601cc47a2 --- /dev/null +++ b/lib/v2/csdn/blog.js @@ -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, + }; +}; diff --git a/lib/v2/csdn/maintainer.js b/lib/v2/csdn/maintainer.js new file mode 100644 index 000000000..17cd520cd --- /dev/null +++ b/lib/v2/csdn/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/blog': ['Jkker'], +}; diff --git a/lib/v2/csdn/radar.js b/lib/v2/csdn/radar.js new file mode 100644 index 000000000..47939c67c --- /dev/null +++ b/lib/v2/csdn/radar.js @@ -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', + }, + ], + }, +}; diff --git a/lib/v2/csdn/router.js b/lib/v2/csdn/router.js new file mode 100644 index 000000000..32d2db445 --- /dev/null +++ b/lib/v2/csdn/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/blog/:user', require('./blog')); +};