fix: 修正微信公众号路由(传送门来源以及CareerEngine来源)中的图片链接 (#4590)

This commit is contained in:
lightyears
2020-04-28 23:42:08 +08:00
committed by GitHub
parent 853f00ee25
commit 4a3ac0ce45
2 changed files with 15 additions and 2 deletions

View File

@@ -12,10 +12,18 @@ module.exports = async (ctx) => {
const response = await got.get(item.link);
const $ = cheerio.load(response.data);
const post = $('.post');
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(),
description: post.html(),
pubDate: item.pubDate,
link: item.link,
};

View File

@@ -30,7 +30,12 @@ module.exports = async (ctx) => {
article('#js_content img').each((index, elem) => {
const $elem = article(elem);
$elem.attr('referrerpolicy', 'no-referrer');
const imgSrc = $elem.attr('data-original');
if (imgSrc) {
const realSrc = imgSrc.replace(/^https:\/\/img.chuansongme.com\//, 'https://mmbiz.qpic.cn/');
$elem.attr('src', realSrc);
}
});
const single = {