From 6316ff1a4ff82add44e2d63bdc473c73721d1ec1 Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 9 Dec 2022 02:25:44 +0500 Subject: [PATCH] feat(route): freewechat (#11419) --- docs/new-media.md | 26 +++++++++----- lib/utils/wechat-mp.js | 1 + lib/v2/freewechat/maintainer.js | 3 ++ lib/v2/freewechat/profile.js | 61 +++++++++++++++++++++++++++++++++ lib/v2/freewechat/radar.js | 13 +++++++ lib/v2/freewechat/router.js | 3 ++ 6 files changed, 99 insertions(+), 8 deletions(-) create mode 100644 lib/v2/freewechat/maintainer.js create mode 100644 lib/v2/freewechat/profile.js create mode 100644 lib/v2/freewechat/radar.js create mode 100644 lib/v2/freewechat/router.js diff --git a/docs/new-media.md b/docs/new-media.md index 46f9a7cc1a..bab15d707a 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -3884,32 +3884,32 @@ column 为 third 时可选的 category: -### 公众号 (优读来源) +### 公众号(优读来源) -### 公众号 (二十次幂来源) +### 公众号(二十次幂来源) -### 公众号 (微阅读来源) +### 公众号(微阅读来源) ::: warning 注意 由于使用了一些针对反爬的缓解措施,本路由响应较慢。默认只抓取前 5 条,可通过 `?limit=` 改变(不推荐,容易被反爬)。\ -该网站使用 IP 甄别访客,且应用严格的每日阅读量限额 (约 15 次),请自建并确保正确配置缓存;如使用内存缓存而非 Redis 缓存,请增大缓存容量。该限额足够订阅至少 3 个公众号 (假设公众号每日仅更新一次);首页 / 分类页更新相当频繁,不推荐订阅。 +该网站使用 IP 甄别访客,且应用严格的每日阅读量限额(约 15 次),请自建并确保正确配置缓存;如使用内存缓存而非 Redis 缓存,请增大缓存容量。该限额足够订阅至少 3 个公众号 (假设公众号每日仅更新一次);首页 / 分类页更新相当频繁,不推荐订阅。 ::: -### 公众号 (wxnmh.com 来源) +### 公众号(wxnmh.com 来源) -### 公众号 (wechat-feeds 来源) +### 公众号(wechat-feeds 来源) ::: warning 注意 @@ -3919,14 +3919,18 @@ wechat-feeds 来源[已停止更新](https://github.com/hellodword/wechat-feeds/ -### 公众号 (feeddd 来源) +### 公众号(feeddd 来源)) -### 公众号 (公众号 360 来源) +### 公众号(公众号 360 来源) 见 [#公众号 360](#gong-zhong-hao-360) +### 公众号(自由微信来源) + +见 [#自由微信](#zi-you-wei-xin) + ### 公众号栏目 (非推送 & 历史消息) @@ -4579,3 +4583,9 @@ QueryString: | | zh-hk | zh-tw | + +## 自由微信 + +### 公众号 + + diff --git a/lib/utils/wechat-mp.js b/lib/utils/wechat-mp.js index 2c87955f6e..b2c743a24f 100644 --- a/lib/utils/wechat-mp.js +++ b/lib/utils/wechat-mp.js @@ -9,6 +9,7 @@ * lib/v2/sdu/cs * lib/v2/nua/utils * lib/v2/hrbeu + * lib/v2/freewechat * * If your new route is not in the above folders, please add it to the list. * diff --git a/lib/v2/freewechat/maintainer.js b/lib/v2/freewechat/maintainer.js new file mode 100644 index 0000000000..ef089ad7ec --- /dev/null +++ b/lib/v2/freewechat/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/profile/:id': ['TonyRL'], +}; diff --git a/lib/v2/freewechat/profile.js b/lib/v2/freewechat/profile.js new file mode 100644 index 0000000000..49a1b55332 --- /dev/null +++ b/lib/v2/freewechat/profile.js @@ -0,0 +1,61 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); +const { fixArticleContent } = require('@/utils/wechat-mp'); +const baseUrl = 'https://freewechat.com'; + +module.exports = async (ctx) => { + const { id } = ctx.params; + const url = `${baseUrl}/profile/${id}`; + const { data: response } = await got(url); + const $ = cheerio.load(response); + const author = $('h2').text().trim(); + + const list = $('.main') + .toArray() + .slice(0, -1) // last item is a template + .map((item) => { + item = $(item); + return { + title: item.find('a').text(), + author, + link: `${baseUrl}${item.find('a').attr('href')}`, + description: item.find('.preview').text(), + }; + }); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const response = await got(item.link, { + headers: { + Referer: url, + }, + }); + const $ = cheerio.load(response.data); + + $('.js_img_placeholder').remove(); + $('amp-img').each((_, e) => { + e = $(e); + e.replaceWith(``); + }); + $('amp-video').each((_, e) => { + e = $(e); + e.replaceWith(``); + }); + + item.description = fixArticleContent($('#js_content')); + item.pubDate = timezone(parseDate($('#publish_time').text()), +8); + return item; + }) + ) + ); + + ctx.state.data = { + title: $('head title').text(), + link: url, + image: 'https://freewechat.com/favicon.ico', + item: items, + }; +}; diff --git a/lib/v2/freewechat/radar.js b/lib/v2/freewechat/radar.js new file mode 100644 index 0000000000..e387a08225 --- /dev/null +++ b/lib/v2/freewechat/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'freewechat.com': { + _name: '自由微信', + '.': [ + { + title: '公众号', + docs: 'https://docs.rsshub.app/new-media.html#zi-you-wei-xin', + source: ['/profile/:id'], + target: '/freewechat/profile/:id', + }, + ], + }, +}; diff --git a/lib/v2/freewechat/router.js b/lib/v2/freewechat/router.js new file mode 100644 index 0000000000..e39f9e10b5 --- /dev/null +++ b/lib/v2/freewechat/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/profile/:id', require('./profile')); +};