From 7e3e034b562b755337393d179debc0584daa8a6b Mon Sep 17 00:00:00 2001 From: kaiix Date: Sun, 8 Jan 2023 02:30:17 +0800 Subject: [PATCH] feat(route): hackmd (#11560) * Add HackMD RSS source * Adapt to v2 router & minor fixes Co-authored-by: Yukai Huang --- docs/en/programming.md | 6 ++++++ docs/programming.md | 6 ++++++ lib/v2/hackmd/maintainer.js | 3 +++ lib/v2/hackmd/profile.js | 24 ++++++++++++++++++++++++ lib/v2/hackmd/radar.js | 13 +++++++++++++ lib/v2/hackmd/router.js | 3 +++ 6 files changed, 55 insertions(+) create mode 100644 lib/v2/hackmd/maintainer.js create mode 100644 lib/v2/hackmd/profile.js create mode 100644 lib/v2/hackmd/radar.js create mode 100644 lib/v2/hackmd/router.js diff --git a/docs/en/programming.md b/docs/en/programming.md index 5766c1ef2..4b49d215e 100644 --- a/docs/en/programming.md +++ b/docs/en/programming.md @@ -273,6 +273,12 @@ Subscribe to the updates (threads and submission) from a paritcular Hacker News +## HackMD + +### Profile + + + ## Hex-Rays ### Hex-Rays News diff --git a/docs/programming.md b/docs/programming.md index c0bb6329a..1481dd168 100644 --- a/docs/programming.md +++ b/docs/programming.md @@ -389,6 +389,12 @@ GitHub 官方也提供了一些 RSS: +## HackMD + +### Profile + + + ## HelloGitHub ### 热门 diff --git a/lib/v2/hackmd/maintainer.js b/lib/v2/hackmd/maintainer.js new file mode 100644 index 000000000..7929bc7a2 --- /dev/null +++ b/lib/v2/hackmd/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/profile/:path': ['Yukaii', 'kaiix'], +}; diff --git a/lib/v2/hackmd/profile.js b/lib/v2/hackmd/profile.js new file mode 100644 index 000000000..3d057a40f --- /dev/null +++ b/lib/v2/hackmd/profile.js @@ -0,0 +1,24 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const path = ctx.params.path; + + const response = await got({ + method: 'get', + url: `https://hackmd.io/api/@${path}/overview`, + }); + const data = response.data; + + const profile = data.user || data.team; + ctx.state.data = { + title: `${profile.name}'s Profile`, + link: `https://hackmd.io/@${path}`, + description: `${profile.name}'s profile on HackMD`, + item: data.notes.map((note) => ({ + title: note.title, + description: `
${note.content}
`, + pubDate: new Date(note.publishedAt).toUTCString(), + link: `https://hackmd.io/@${path}/${note.permalink || note.shortId}`, + })), + }; +}; diff --git a/lib/v2/hackmd/radar.js b/lib/v2/hackmd/radar.js new file mode 100644 index 000000000..0cc0e604f --- /dev/null +++ b/lib/v2/hackmd/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'hackmd.io': { + _name: 'HackMD', + '.': [ + { + title: 'Profile', + docs: 'http://docs.rsshub.app/programming.html#hackmd', + source: ['/:profile'], + target: (params) => `/hackmd/profile/${params.replace('@', '')}`, + }, + ], + }, +}; diff --git a/lib/v2/hackmd/router.js b/lib/v2/hackmd/router.js new file mode 100644 index 000000000..e5cf53dc7 --- /dev/null +++ b/lib/v2/hackmd/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/profile/:path', require('./profile')); +};