From 5f9018c3dfd2e064f8e701c8b759e20b1fdc3d8d Mon Sep 17 00:00:00 2001 From: Jerry K Jia Date: Tue, 16 Aug 2022 20:30:22 -0400 Subject: [PATCH] =?UTF-8?q?feat(routes):=20CSDN=20=E5=8D=9A=E5=AE=A2=20(#1?= =?UTF-8?q?0447)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(routes): CSDN Blog * fix(docs): add CSDN Blog paramsDesc --- docs/blog.md | 7 +++++++ docs/en/blog.md | 7 +++++++ lib/v2/csdn/blog.js | 39 +++++++++++++++++++++++++++++++++++++++ lib/v2/csdn/maintainer.js | 3 +++ lib/v2/csdn/radar.js | 13 +++++++++++++ lib/v2/csdn/router.js | 3 +++ 6 files changed, 72 insertions(+) create mode 100644 lib/v2/csdn/blog.js create mode 100644 lib/v2/csdn/maintainer.js create mode 100644 lib/v2/csdn/radar.js create mode 100644 lib/v2/csdn/router.js 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')); +};