From fcce45388f88007b18c3bd000bc913238d0e000c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=AA=E9=B1=BC?= Date: Mon, 22 Jul 2019 15:55:02 +0800 Subject: [PATCH] feat: original link from WeChat and better performance (#2660) * fix: original link from wechat * fix: original link from wechat * fix: original link from wechat * fix: original link from WeChat and better performance --- lib/routes/tencent/wechat/wemp.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/routes/tencent/wechat/wemp.js b/lib/routes/tencent/wechat/wemp.js index eadfae64db..ae96f8269b 100644 --- a/lib/routes/tencent/wechat/wemp.js +++ b/lib/routes/tencent/wechat/wemp.js @@ -1,4 +1,5 @@ const got = require('@/utils/got'); +const he = require('he'); const cheerio = require('cheerio'); const date = require('@/utils/date'); @@ -38,15 +39,20 @@ module.exports = async (ctx) => { .attr('href')}`; const response = await ctx.cache.tryGet(link, async () => (await got.get(link)).data); - const article = cheerio.load(response); + const matchs = /"(url|temp_url)":"([^"]+mp\.weixin\.qq\.com[^"]+)"/.exec(response); + let weixinLink = ''; + if (matchs && matchs[2]) { + weixinLink = he.unescape(unescape(matchs[2].replace(/\\u/g, '%u'))); + } + const single = { title: $(e) .find('.post-item__title') .text() .trim(), - link, + link: weixinLink || link, description: article('#content').html(), pubDate, author,