From f796ff1d54fef090ddbb5e1cff8dd16453b95543 Mon Sep 17 00:00:00 2001 From: lyrl Date: Mon, 5 Dec 2022 23:24:21 +0800 Subject: [PATCH] feat(route): add panda feed (#11367) * * feat: add panda feed * * feat: document table inside the Route tag * * feat: panda route Introduce limit parameter * docs(ROUTE): add /panda/feeds/:id parameter description * refactor(ROUTE): Use a more appropriate path /usepanda/feeds/:id instead of /panda/feeds/:id * refactor(ROUTE): Remove non-existent attributes tags * feat(ROUTE): fix limit param * fix: add missing radar --- docs/en/other.md | 13 ++++++++++++- docs/other.md | 12 ++++++++++++ lib/v2/usepanda/index.js | 26 ++++++++++++++++++++++++++ lib/v2/usepanda/maintainer.js | 3 +++ lib/v2/usepanda/radar.js | 11 +++++++++++ lib/v2/usepanda/router.js | 3 +++ 6 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 lib/v2/usepanda/index.js create mode 100644 lib/v2/usepanda/maintainer.js create mode 100644 lib/v2/usepanda/radar.js create mode 100644 lib/v2/usepanda/router.js diff --git a/docs/en/other.md b/docs/en/other.md index 658420401..2b0adc59b 100644 --- a/docs/en/other.md +++ b/docs/en/other.md @@ -166,6 +166,18 @@ Official Website: +## Panda + +### Feeds + + + +| Channel | feedId | +| -------------------- | ------------------------ | +| Github | 5718e53e7a84fb1901e059cc | + + + ## Parcel Tracking ### Hermes UK @@ -266,4 +278,3 @@ Refer to [the list of supported currencies](https://wise.com/tools/exchange-rate ### User - diff --git a/docs/other.md b/docs/other.md index d23ccc8d5..38fe6ef34 100644 --- a/docs/other.md +++ b/docs/other.md @@ -242,6 +242,18 @@ pageClass: routes +## Panda + +### Feeds + + + +| 频道 | feedId | +| ----------- | ------------------------ | +| Github 热门推荐 | 5718e53e7a84fb1901e059cc | + + + ## Parcel Tracking ### Hermes UK diff --git a/lib/v2/usepanda/index.js b/lib/v2/usepanda/index.js new file mode 100644 index 000000000..3b117b864 --- /dev/null +++ b/lib/v2/usepanda/index.js @@ -0,0 +1,26 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const feedId = ctx.params.id; + const limit = ctx.query.limit ?? 30; // 默认30条 + + const rootUrl = 'https://api-panda.com/v4/'; + const apiUrl = `${rootUrl}articles?feeds=${feedId}&limit=${limit}&page=1&sort=popular`; + + const { data } = await got(apiUrl); + + const items = data.map((item) => ({ + title: `${item.title} 🌟 ${item.source.likesCount}`, + author: item.source.username, + pubDate: parseDate(item.source.createdAt), + link: item.source.targetUrl, + description: item.description, + })); + + ctx.state.data = { + title: 'Panda Feeds', + link: 'https://usepanda.com/', + item: items, + }; +}; diff --git a/lib/v2/usepanda/maintainer.js b/lib/v2/usepanda/maintainer.js new file mode 100644 index 000000000..b60043cae --- /dev/null +++ b/lib/v2/usepanda/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/feeds/:id': ['lyrl'], +}; diff --git a/lib/v2/usepanda/radar.js b/lib/v2/usepanda/radar.js new file mode 100644 index 000000000..2981a3198 --- /dev/null +++ b/lib/v2/usepanda/radar.js @@ -0,0 +1,11 @@ +module.exports = { + 'usepanda.com': { + _name: 'Panda', + '.': [ + { + title: 'Feeds', + docs: 'https://docs.rsshub.app/other.html#panda', + }, + ], + }, +}; diff --git a/lib/v2/usepanda/router.js b/lib/v2/usepanda/router.js new file mode 100644 index 000000000..77062d911 --- /dev/null +++ b/lib/v2/usepanda/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/feeds/:id', require('./index')); +};