diff --git a/docs/new-media.md b/docs/new-media.md
index b29581aaa2..24ade14222 100644
--- a/docs/new-media.md
+++ b/docs/new-media.md
@@ -3344,7 +3344,7 @@ column 为 third 时可选的 category:
### 公众号(CareerEngine 来源)
-
+
### 公众号(Telegram 频道来源)
@@ -3380,7 +3380,7 @@ column 为 third 时可选的 category:
### 公众号 (wxnmh.com 来源)
-
+
### 公众号 (wechat-feeds 来源)
diff --git a/lib/routes/tencent/wechat/_README b/lib/routes/tencent/wechat/_README
new file mode 100644
index 0000000000..7b066658f2
--- /dev/null
+++ b/lib/routes/tencent/wechat/_README
@@ -0,0 +1 @@
+Make sure you read lib/utils/wechat-mp.js before adding a new route.
diff --git a/lib/routes/tencent/wechat/feeds.js b/lib/routes/tencent/wechat/feeds.js
index 8edfbb3fa6..799ad0a16e 100644
--- a/lib/routes/tencent/wechat/feeds.js
+++ b/lib/routes/tencent/wechat/feeds.js
@@ -1,42 +1,18 @@
const parser = require('@/utils/rss-parser');
-const got = require('@/utils/got');
-const cheerio = require('cheerio');
+const { finishArticleItem } = require('@/utils/wechat-mp');
module.exports = async (ctx) => {
const { id } = ctx.params;
const link = `https://github.com/hellodword/wechat-feeds/raw/feeds/${id}.xml`;
const feed = await parser.parseURL(link);
- const items = await Promise.all(
- feed.items.map(async (item) => {
- const cache = await ctx.cache.get(item.link);
- if (cache) {
- return Promise.resolve(JSON.parse(cache));
- }
-
- const response = await got.get(item.link);
-
- const $ = cheerio.load(response.data);
- const post = $('#js_content');
-
- post.find('img').each((_, img) => {
- const dataSrc = $(img).attr('data-src');
- if (dataSrc) {
- $(img).attr('src', dataSrc);
- }
- });
-
- const single = {
- title: item.title,
- description: post.html(),
- pubDate: new Date(item.pubDate),
- link: item.link,
- };
-
- ctx.cache.set(item.link, JSON.stringify(single));
- return Promise.resolve(single);
- })
- );
+ const items = feed.items.map((item) => ({
+ title: item.title,
+ pubDate: new Date(item.pubDate),
+ link: item.link,
+ guid: item.link,
+ }));
+ await Promise.all(items.map(async (item) => await finishArticleItem(ctx, item)));
ctx.state.data = {
title: feed.title,
diff --git a/lib/routes/tencent/wechat/mp.js b/lib/routes/tencent/wechat/mp.js
index a59525c0f8..308fb2e121 100755
--- a/lib/routes/tencent/wechat/mp.js
+++ b/lib/routes/tencent/wechat/mp.js
@@ -1,6 +1,8 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const dayjs = require('dayjs');
+const { finishArticleItem } = require('@/utils/wechat-mp');
+
module.exports = async (ctx) => {
const { biz, hid, cid } = ctx.params;
let cidurl = '';
@@ -26,32 +28,11 @@ module.exports = async (ctx) => {
const mptitle = $('div.articles_header').find('a').text() + `|` + $('div.articles_header > h2.rich_media_title').text();
const articledata = await Promise.all(
list.map(async (item) => {
- const link = item.link.replace('http://', 'https://');
- const cache = await ctx.cache.get(link);
- if (cache) {
- return Promise.resolve(JSON.parse(cache));
- }
- const response2 = await got({
- method: 'get',
- url: link,
- });
- const articleHtml = response2.data;
- const $2 = cheerio.load(articleHtml);
- $2('img').removeAttr('src');
- $2('div#js_profile_qrcode').remove();
-
- const content = $2('div#js_content.rich_media_content')
- .html()
- .replace('iframe/preview.html?width=500&height=375&', 'txp/iframe/player.html?')
- .replace('