From ca54298e11d43f17a0b6da187e579d4313c2603d Mon Sep 17 00:00:00 2001 From: Tony Date: Wed, 15 Feb 2023 14:32:33 +0100 Subject: [PATCH] feat(route): wechat2rss (#11874) --- docs/new-media.md | 6 +++++- lib/v2/wechat/maintainer.js | 1 + lib/v2/wechat/radar.js | 11 +++++++++++ lib/v2/wechat/router.js | 1 + lib/v2/wechat/wechat2rss.js | 28 ++++++++++++++++++++++++++++ 5 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 lib/v2/wechat/wechat2rss.js diff --git a/docs/new-media.md b/docs/new-media.md index 8dbb6ebce..2d5fb6a80 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -3944,12 +3944,16 @@ column 为 third 时可选的 category: ### 公众号(feeddd 来源) - + ### 公众号(自由微信来源) 见 [#自由微信](#zi-you-wei-xin) +### 公众号(Wechat2RSS 来源) + + + ### 公众号栏目 (非推送 & 历史消息) diff --git a/lib/v2/wechat/maintainer.js b/lib/v2/wechat/maintainer.js index 771c9b2da..78f12b307 100644 --- a/lib/v2/wechat/maintainer.js +++ b/lib/v2/wechat/maintainer.js @@ -9,5 +9,6 @@ module.exports = { '/mp/msgalbum/:biz/:aid': ['MisteryMonster'], '/tgchannel/:id/:mpName?/:searchQueryType?': ['LogicJake', 'Rongronggg9'], '/uread/:userid': ['kt286'], + '/wechat2rss/:id': ['TonyRL'], '/wxnmh/:id': ['laampui'], }; diff --git a/lib/v2/wechat/radar.js b/lib/v2/wechat/radar.js index ee5347801..798dcf5e1 100644 --- a/lib/v2/wechat/radar.js +++ b/lib/v2/wechat/radar.js @@ -73,4 +73,15 @@ module.exports = { }, ], }, + 'xlab.app': { + _name: '微信', + wechat2rss: [ + { + title: '公众号(wechat2rss 来源)', + docs: 'https://docs.rsshub.app/new-media.html#wei-xin', + source: ['/feed/:id'], + target: (params) => `/wechat/wechat2rss/${params.id.replace('.xml', '')}`, + }, + ], + }, }; diff --git a/lib/v2/wechat/router.js b/lib/v2/wechat/router.js index 19953e0d4..62ae12cda 100644 --- a/lib/v2/wechat/router.js +++ b/lib/v2/wechat/router.js @@ -9,5 +9,6 @@ module.exports = function (router) { router.get('/mp/msgalbum/:biz/:aid', require('./msgalbum')); router.get('/tgchannel/:id/:mpName?/:searchQueryType?', require('./tgchannel')); router.get('/uread/:userid', require('./uread')); + router.get('/wechat2rss/:id', require('./wechat2rss')); router.get('/wxnmh/:id', require('./wxnmh')); }; diff --git a/lib/v2/wechat/wechat2rss.js b/lib/v2/wechat/wechat2rss.js new file mode 100644 index 000000000..618fa051b --- /dev/null +++ b/lib/v2/wechat/wechat2rss.js @@ -0,0 +1,28 @@ +const parser = require('@/utils/rss-parser'); +const { parseDate } = require('@/utils/parse-date'); +const { finishArticleItem } = require('@/utils/wechat-mp'); + +module.exports = async (ctx) => { + const { id } = ctx.params; + + const baseUrl = 'https://wechat2rss.xlab.app'; + const feedUrl = `${baseUrl}/feed/${id}.xml`; + + const { title, link, description, image, items: item } = await parser.parseURL(feedUrl); + + let items = item.map((i) => ({ + title: i.title, + pubDate: parseDate(i.pubDate), + link: i.link, + })); + + items = await Promise.all(items.map((item) => finishArticleItem(ctx, item))); + + ctx.state.data = { + title, + link, + description, + image: image.url, + item: items, + }; +};