Handle gif in feeds (#1129)

This commit is contained in:
Henry Wang 2018-11-13 02:51:16 +00:00 committed by DIYgod
parent 076ea96792
commit 43d96c4730
1 changed files with 12 additions and 2 deletions

View File

@ -39,8 +39,18 @@ module.exports = async (ctx) => {
// 处理文章图片
content.find('figure.e-image').each((i, e) => {
let src = $(e).find('picture > img')[0].attribs.srcset;
src = src.match(/(?<=320w,).*?(?=520w)/g)[0].trim();
let src;
// 处理 jpeg, png
if ($(e).find('picture > source').length > 0) {
src = $(e)
.find('picture > img')[0]
.attribs.srcset.match(/(?<=320w,).*?(?=520w)/g)[0]
.trim();
} else if ($(e).find('img.c-dynamic-image').length > 0) {
// 处理 gif
src = $(e).find('span.e-image__image')[0].attribs['data-original'];
}
$(`<img src='${src}'>`).insertBefore(e);
$(e).remove();