From 9d9926d0bfdfa0005f4e43c07879c8c55ff8497a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=BB=E5=B9=B3=E7=94=9F?= Date: Thu, 21 Apr 2022 21:40:16 +0800 Subject: [PATCH] =?UTF-8?q?fix(utils):=20=E4=BF=AE=E5=A4=8D=E6=8A=93?= =?UTF-8?q?=E5=8F=96=E5=BE=AE=E4=BF=A1=E5=B7=B2=E5=88=A0=E9=99=A4=E6=96=87?= =?UTF-8?q?=E7=AB=A0=E6=97=B6=E9=81=87=E5=88=B0=E7=9A=84=E6=8A=A5=E9=94=99?= =?UTF-8?q?=20(#9589)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(utils): 支持微信公众号单图片文章抓取 * fix(utils): 支持输出微信公众号转载文章阅读原文链接 * fix(utils): 修复抓取微信已删除文章时遇到的报错 * refactor: migrate to v2 Co-authored-by: blankyu(于海洋) --- docs/new-media.md | 8 --- docs/programming.md | 8 +++ lib/router.js | 24 +++---- lib/routes/tencent/wechat/_README | 1 - .../tencent/wechat/miniprogram/framework.js | 6 +- lib/utils/wechat-mp.js | 3 +- lib/{routes/tencent => v2}/wechat/announce.js | 5 +- lib/{routes/tencent => v2}/wechat/ce.js | 0 lib/{routes/tencent => v2}/wechat/ershcimi.js | 0 lib/{routes/tencent => v2}/wechat/feeds.js | 0 lib/v2/wechat/maintainer.js | 12 +++- lib/{routes/tencent => v2}/wechat/mp.js | 0 lib/{routes/tencent => v2}/wechat/msgalbum.js | 0 lib/v2/wechat/radar.js | 72 +++++++++++++++++-- lib/v2/wechat/router.js | 12 +++- .../tencent => v2}/wechat/tgchannel.js | 0 lib/{routes/tencent => v2}/wechat/uread.js | 0 lib/{routes/tencent => v2}/wechat/wemp.js | 0 lib/{routes/tencent => v2}/wechat/wxnmh.js | 0 19 files changed, 117 insertions(+), 34 deletions(-) delete mode 100644 lib/routes/tencent/wechat/_README rename lib/{routes/tencent => v2}/wechat/announce.js (88%) rename lib/{routes/tencent => v2}/wechat/ce.js (100%) rename lib/{routes/tencent => v2}/wechat/ershcimi.js (100%) rename lib/{routes/tencent => v2}/wechat/feeds.js (100%) rename lib/{routes/tencent => v2}/wechat/mp.js (100%) rename lib/{routes/tencent => v2}/wechat/msgalbum.js (100%) rename lib/{routes/tencent => v2}/wechat/tgchannel.js (100%) rename lib/{routes/tencent => v2}/wechat/uread.js (100%) rename lib/{routes/tencent => v2}/wechat/wemp.js (100%) rename lib/{routes/tencent => v2}/wechat/wxnmh.js (100%) diff --git a/docs/new-media.md b/docs/new-media.md index 277c4b4ee..828d86813 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -3447,14 +3447,6 @@ wechat-feeds 来源[已停止更新](https://github.com/hellodword/wechat-feeds/ -### 公众平台系统公告栏目 - - - -### 小程序插件 - - - ## 维基百科 ### 中国大陆新闻动态 diff --git a/docs/programming.md b/docs/programming.md index 36de6faae..02e0bd2b4 100644 --- a/docs/programming.md +++ b/docs/programming.md @@ -1036,6 +1036,10 @@ GitHub 官方也提供了一些 RSS: ## 微信小程序 +### 公众平台系统公告栏目 + + + ### 基础库更新日志 @@ -1044,6 +1048,10 @@ GitHub 官方也提供了一些 RSS: +### 小程序插件 + + + ### 云开发更新日志 diff --git a/lib/router.js b/lib/router.js index 94a3e023c..01112c31c 100644 --- a/lib/router.js +++ b/lib/router.js @@ -421,20 +421,18 @@ router.get('/tucaoqq/post/:project/:key', lazyloadRouteHandler('./routes/tencent // Bugly SDK router.get('/bugly/changelog/:platform', lazyloadRouteHandler('./routes/tencent/bugly/changelog')); -// wechat -router.get('/wechat/wemp/:id', lazyloadRouteHandler('./routes/tencent/wechat/wemp')); -router.get('/wechat/csm/:id', lazyloadRouteHandler('./routes/tencent/wechat/csm')); -router.get('/wechat/ce/:id', lazyloadRouteHandler('./routes/tencent/wechat/ce')); -router.get('/wechat/announce', lazyloadRouteHandler('./routes/tencent/wechat/announce')); +// wechat migrated to v2 +// router.get('/wechat/wemp/:id', lazyloadRouteHandler('./routes/tencent/wechat/wemp')); +// router.get('/wechat/ce/:id', lazyloadRouteHandler('./routes/tencent/wechat/ce')); +// router.get('/wechat/announce', lazyloadRouteHandler('./routes/tencent/wechat/announce')); router.get('/wechat/miniprogram/plugins', lazyloadRouteHandler('./routes/tencent/wechat/miniprogram/plugins')); -router.get('/wechat/tgchannel/:id/:mpName?/:searchQueryType?', lazyloadRouteHandler('./routes/tencent/wechat/tgchannel')); -router.get('/wechat/uread/:userid', lazyloadRouteHandler('./routes/tencent/wechat/uread')); -router.get('/wechat/ershicimi/:id', lazyloadRouteHandler('./routes/tencent/wechat/ershcimi')); -router.get('/wechat/wjdn/:id', lazyloadRouteHandler('./routes/tencent/wechat/wjdn')); -router.get('/wechat/wxnmh/:id', lazyloadRouteHandler('./routes/tencent/wechat/wxnmh')); -router.get('/wechat/mp/homepage/:biz/:hid/:cid?', lazyloadRouteHandler('./routes/tencent/wechat/mp')); -router.get('/wechat/mp/msgalbum/:biz/:aid', lazyloadRouteHandler('./routes/tencent/wechat/msgalbum')); -router.get('/wechat/feeds/:id', lazyloadRouteHandler('./routes/tencent/wechat/feeds')); +// router.get('/wechat/tgchannel/:id/:mpName?/:searchQueryType?', lazyloadRouteHandler('./routes/tencent/wechat/tgchannel')); +// router.get('/wechat/uread/:userid', lazyloadRouteHandler('./routes/tencent/wechat/uread')); +// router.get('/wechat/ershicimi/:id', lazyloadRouteHandler('./routes/tencent/wechat/ershcimi')); +// router.get('/wechat/wxnmh/:id', lazyloadRouteHandler('./routes/tencent/wechat/wxnmh')); +// router.get('/wechat/mp/homepage/:biz/:hid/:cid?', lazyloadRouteHandler('./routes/tencent/wechat/mp')); +// router.get('/wechat/mp/msgalbum/:biz/:aid', lazyloadRouteHandler('./routes/tencent/wechat/msgalbum')); +// router.get('/wechat/feeds/:id', lazyloadRouteHandler('./routes/tencent/wechat/feeds')); // All the Flight Deals router.get('/atfd/:locations/:nearby?', lazyloadRouteHandler('./routes/atfd/index')); diff --git a/lib/routes/tencent/wechat/_README b/lib/routes/tencent/wechat/_README deleted file mode 100644 index 7b066658f..000000000 --- a/lib/routes/tencent/wechat/_README +++ /dev/null @@ -1 +0,0 @@ -Make sure you read lib/utils/wechat-mp.js before adding a new route. diff --git a/lib/routes/tencent/wechat/miniprogram/framework.js b/lib/routes/tencent/wechat/miniprogram/framework.js index a0d453044..fb104d9df 100644 --- a/lib/routes/tencent/wechat/miniprogram/framework.js +++ b/lib/routes/tencent/wechat/miniprogram/framework.js @@ -1,5 +1,7 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); module.exports = async (ctx) => { const link = `https://developers.weixin.qq.com/miniprogram/dev/framework/release/`; @@ -16,14 +18,14 @@ module.exports = async (ctx) => { ctx.state.data = { title: name, link, - item: $('#docContent .content h3') + item: $('#docContent .content h2') .map((_, item) => { item = $(item); const title = item.text().replace(/[\s|#]/g, ''); return { title, description: item.next().html(), - pubDate: new Date(new RegExp(/\d{4}-\d{2}-\d{2}/).exec(title) + ' GMT+8').toUTCString(), + pubDate: timezone(parseDate(new RegExp(/\d{4}-\d{2}-\d{2}/).exec(title)), +8), link: link + item.find('a.header-anchor').attr('href'), }; }) diff --git a/lib/utils/wechat-mp.js b/lib/utils/wechat-mp.js index ba948c7aa..e6729a325 100644 --- a/lib/utils/wechat-mp.js +++ b/lib/utils/wechat-mp.js @@ -2,7 +2,6 @@ * Author: @Rongronggg9 * * There are at least three folders which are relevant with WeChat MP (Official Account Platform / Media Platform): - * lib/route/tencent/wechat * lib/v2/wechat * lib/v2/gzh360 * lib/v2/sdu/cs @@ -181,7 +180,7 @@ const fetchArticle = async (ctx, url, bypassHostCheck = false) => { const response = await got(url); const $ = cheerio.load(response.data); - const title = $('meta[property="og:title"]').attr('content').replace(/\\r/g, '').replace(/\\n/g, ' '); + const title = ($('meta[property="og:title"]').attr('content') || '').replace(/\\r/g, '').replace(/\\n/g, ' '); const author = $('meta[name=author]').attr('content'); let summary = $('meta[name=description]').attr('content'); summary = summary !== title ? summary : ''; diff --git a/lib/routes/tencent/wechat/announce.js b/lib/v2/wechat/announce.js similarity index 88% rename from lib/routes/tencent/wechat/announce.js rename to lib/v2/wechat/announce.js index ce4db72c0..eb9f6dedd 100644 --- a/lib/routes/tencent/wechat/announce.js +++ b/lib/v2/wechat/announce.js @@ -1,5 +1,6 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); module.exports = async (ctx) => { const { data: htmlString } = await got({ @@ -20,13 +21,13 @@ module.exports = async (ctx) => { title: `${time} ${title}`, link: `https://mp.weixin.qq.com${$link.attr('href')}`, description: title, - pubDate: new Date(time).toUTCString(), + pubDate: parseDate(time), }); }); ctx.state.data = { title: '微信公众平台-系统公告栏目', - link: 'https://mp.weixin.qq.com/cgi-bin/announce?action=getannouncementlist&lang=zh_CN&token=', + link: 'https://mp.weixin.qq.com/cgi-bin/announce?action=getannouncementlist&lang=zh_CN', item: announceList, }; }; diff --git a/lib/routes/tencent/wechat/ce.js b/lib/v2/wechat/ce.js similarity index 100% rename from lib/routes/tencent/wechat/ce.js rename to lib/v2/wechat/ce.js diff --git a/lib/routes/tencent/wechat/ershcimi.js b/lib/v2/wechat/ershcimi.js similarity index 100% rename from lib/routes/tencent/wechat/ershcimi.js rename to lib/v2/wechat/ershcimi.js diff --git a/lib/routes/tencent/wechat/feeds.js b/lib/v2/wechat/feeds.js similarity index 100% rename from lib/routes/tencent/wechat/feeds.js rename to lib/v2/wechat/feeds.js diff --git a/lib/v2/wechat/maintainer.js b/lib/v2/wechat/maintainer.js index 6924eabb1..0f87b0a5c 100644 --- a/lib/v2/wechat/maintainer.js +++ b/lib/v2/wechat/maintainer.js @@ -1,4 +1,14 @@ module.exports = { - '/feeddd/:id': ['TonyRL', 'Rongronggg9'], + '/announce': ['xyqfer'], + '/ce/:id': ['HenryQW'], + '/ershicimi/:id': ['sanmmm'], '/data258/:id?': ['Rongronggg9'], + '/feeddd/:id': ['TonyRL', 'Rongronggg9'], + '/feeds': ['tylinux'], + '/mp/homepage/:biz/:hid/:cid?': ['MisteryMonster'], + '/mp/msgalbum/:biz/:aid': ['MisteryMonster'], + '/tgchannel/:id/:mpName?/:searchQueryType?': ['LogicJake', 'Rongronggg9'], + '/uread/:userid': ['kt286'], + '/wemp/:id': ['HenryQW'], + '/wxnmh/:id': ['laampui'], }; diff --git a/lib/routes/tencent/wechat/mp.js b/lib/v2/wechat/mp.js similarity index 100% rename from lib/routes/tencent/wechat/mp.js rename to lib/v2/wechat/mp.js diff --git a/lib/routes/tencent/wechat/msgalbum.js b/lib/v2/wechat/msgalbum.js similarity index 100% rename from lib/routes/tencent/wechat/msgalbum.js rename to lib/v2/wechat/msgalbum.js diff --git a/lib/v2/wechat/radar.js b/lib/v2/wechat/radar.js index 03b68ec02..f614be15b 100644 --- a/lib/v2/wechat/radar.js +++ b/lib/v2/wechat/radar.js @@ -1,11 +1,23 @@ module.exports = { - 'feeddd.org': { + 'careerengine.us': { + _name: '微信', + posts: [ + { + title: '公众号(CareerEngine 来源)', + docs: 'https://docs.rsshub.app/new-media.html#wei-xin', + source: ['/author/*id/posts'], + target: (params) => `/wechat/ce/${params.id}`, + }, + ], + }, + 'cimidata.com': { _name: '微信', '.': [ { - title: '公众号 (feeddd 来源)', + title: '公众号(二十次幂来源)', docs: 'https://docs.rsshub.app/new-media.html#wei-xin', - source: ['/'], + source: ['/a/:id'], + target: '/wechat/ce/:id', }, ], }, @@ -13,11 +25,63 @@ module.exports = { _name: '微信', mp: [ { - title: '公众号 (微阅读来源)', + title: '公众号(微阅读来源)', docs: 'https://docs.rsshub.app/new-media.html#wei-xin', source: ['/', '/article/category/:id'], target: '/wechat/data258/:id?', }, ], }, + 'feeddd.org': { + _name: '微信', + '.': [ + { + title: '公众号(feeddd 来源)', + docs: 'https://docs.rsshub.app/new-media.html#wei-xin', + source: ['/'], + }, + ], + }, + 'mp.weixin.qq.com': { + _name: '微信', + '.': [ + { + title: '公众平台系统公告栏目', + docs: 'https://docs.rsshub.app/new-media.html#wei-xin', + source: ['/cgi-bin/announce'], + target: '/wechat/announce', + }, + ], + }, + 'privacyhide.com': { + _name: '微信', + wechat: [ + { + title: '公众号(wechat-feeds 来源)', + docs: 'https://docs.rsshub.app/new-media.html#wei-xin', + }, + ], + }, + 'wemp.app': { + _name: '微信', + '.': [ + { + title: '公众号(wemp.app 来源)', + docs: 'https://docs.rsshub.app/new-media.html#wei-xin', + source: ['/accounts/:id'], + target: '/wechat/wemp/:id', + }, + ], + }, + 'wxnmh.com': { + _name: '微信', + '.': [ + { + title: '公众号(wxnmh.com 来源)', + docs: 'https://docs.rsshub.app/new-media.html#wei-xin', + source: ['/:id'], + target: (params) => `/wechat/wxnmh/${params.id.replace('user-', '').replace('.htm', '')}`, + }, + ], + }, }; diff --git a/lib/v2/wechat/router.js b/lib/v2/wechat/router.js index 7af4ca0b6..808f6e3f2 100644 --- a/lib/v2/wechat/router.js +++ b/lib/v2/wechat/router.js @@ -1,4 +1,14 @@ module.exports = function (router) { - router.get('/feeddd/:id', require('./feeddd')); + router.get('/announce', require('./announce')); + router.get('/ce/:id', require('./ce')); router.get('/data258/:id?', require('./data258')); + router.get('/ershicimi/:id', require('./ershcimi')); + router.get('/feeddd/:id', require('./feeddd')); + router.get('/feeds/:id', require('./feeds')); + router.get('/mp/homepage/:biz/:hid/:cid?', require('./mp')); + router.get('/mp/msgalbum/:biz/:aid', require('./msgalbum')); + router.get('/tgchannel/:id/:mpName?/:searchQueryType?', require('./tgchannel')); + router.get('/uread/:userid', require('./uread')); + router.get('/wemp/:id', require('./wemp')); + router.get('/wxnmh/:id', require('./wxnmh')); }; diff --git a/lib/routes/tencent/wechat/tgchannel.js b/lib/v2/wechat/tgchannel.js similarity index 100% rename from lib/routes/tencent/wechat/tgchannel.js rename to lib/v2/wechat/tgchannel.js diff --git a/lib/routes/tencent/wechat/uread.js b/lib/v2/wechat/uread.js similarity index 100% rename from lib/routes/tencent/wechat/uread.js rename to lib/v2/wechat/uread.js diff --git a/lib/routes/tencent/wechat/wemp.js b/lib/v2/wechat/wemp.js similarity index 100% rename from lib/routes/tencent/wechat/wemp.js rename to lib/v2/wechat/wemp.js diff --git a/lib/routes/tencent/wechat/wxnmh.js b/lib/v2/wechat/wxnmh.js similarity index 100% rename from lib/routes/tencent/wechat/wxnmh.js rename to lib/v2/wechat/wxnmh.js