mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
知乎大图 (#756)
Fix #703 只发现了 jpg 和 gif,gif 不需要处理. https://pic2.zhimg.com/v2-aa4e9886c9d2a53c691420391713196a_r.gif https://pic2.zhimg.com/v2-aa4e9886c9d2a53c691420391713196a_hd.gif https://pic2.zhimg.com/v2-aa4e9886c9d2a53c691420391713196a_b.gif
This commit is contained in:
@@ -34,12 +34,12 @@ module.exports = async (ctx) => {
|
||||
switch (item.target.type) {
|
||||
case 'answer':
|
||||
title = detail.question.title;
|
||||
description = detail.content;
|
||||
description = utils.ProcessImage(detail.content);
|
||||
url = `https://www.zhihu.com/question/${detail.question.id}/answer/${detail.id}`;
|
||||
break;
|
||||
case 'article':
|
||||
title = detail.title;
|
||||
description = detail.content;
|
||||
description = utils.ProcessImage(detail.content);
|
||||
url = `https://zhuanlan.zhihu.com/p/${detail.id}`;
|
||||
break;
|
||||
case 'pin':
|
||||
@@ -57,7 +57,7 @@ module.exports = async (ctx) => {
|
||||
url = `https://www.zhihu.com/pin/${detail.id}`;
|
||||
break;
|
||||
case 'question':
|
||||
title = detail.title;
|
||||
title = utils.ProcessImage(detail.detail);
|
||||
description = detail.excerpt;
|
||||
url = `https://www.zhihu.com/question/${detail.id}`;
|
||||
break;
|
||||
|
||||
@@ -24,7 +24,7 @@ module.exports = async (ctx) => {
|
||||
data &&
|
||||
data.map((item) => ({
|
||||
title: item.question.title,
|
||||
description: item.content,
|
||||
description: utils.ProcessImage(item.content),
|
||||
pubDate: new Date(item.created_time * 1000).toUTCString(),
|
||||
link: `https://www.zhihu.com/question/${item.question.id}/answer/${item.id}`,
|
||||
})),
|
||||
|
||||
@@ -33,7 +33,7 @@ module.exports = async (ctx) => {
|
||||
}
|
||||
return {
|
||||
title: item.find('.zm-item-title a').text(),
|
||||
description: `内容:${item.find('textarea').text()}`,
|
||||
description: utils.ProcessImage(item.find('textarea').text()),
|
||||
link: linkUrl,
|
||||
};
|
||||
})
|
||||
|
||||
@@ -36,7 +36,7 @@ module.exports = async (ctx) => {
|
||||
Referer: url,
|
||||
},
|
||||
});
|
||||
item.description = storyDetail.data.body.replace(/<div class="meta">([\s\S]*?)<\/div>/g, '<strong>$1</strong>');
|
||||
item.description = utils.ProcessImage(storyDetail.data.body.replace(/<div class="meta">([\s\S]*?)<\/div>/g, '<strong>$1</strong>'));
|
||||
ctx.cache.set(key, item.description, 24 * 60 * 60);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const axios = require('../../utils/axios');
|
||||
const utils = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const {
|
||||
@@ -17,22 +18,24 @@ module.exports = async (ctx) => {
|
||||
case 'answer':
|
||||
return {
|
||||
title: item.target.question.title,
|
||||
description: `${item.target.author.name}的回答<br/><br/>${item.target.content}`,
|
||||
author: item.target.author.name,
|
||||
description: `${item.target.author.name}的回答<br/><br/>${utils.ProcessImage(item.target.content)}`,
|
||||
pubDate: new Date(item.created_time).toUTCString(),
|
||||
link: `https://www.zhihu.com/question/${item.target.question.id}`,
|
||||
};
|
||||
case 'article':
|
||||
return {
|
||||
title: item.target.title,
|
||||
description: `${item.target.author.name}的文章<br/><br/>${item.target.content}`,
|
||||
pubDate: new Date(item.created_time).toUTCString(),
|
||||
author: item.target.author.name,
|
||||
description: `${item.target.author.name}的文章<br/><br/>${utils.ProcessImage(item.target.content)}`,
|
||||
pubDate: new Date(item.created_time * 1000).toUTCString(),
|
||||
link: `https://zhuanlan.zhihu.com/p/${item.target.id}`,
|
||||
};
|
||||
default:
|
||||
return {
|
||||
title: '未知类型',
|
||||
description: '请点击链接提交issue',
|
||||
pubDate: new Date(item.created_time).toUTCString(),
|
||||
pubDate: new Date(item.created_time * 1000).toUTCString(),
|
||||
link: 'https://github.com/DIYgod/RSSHub/issues',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,29 @@
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = {
|
||||
header: {
|
||||
'x-api-version': '3.0.40',
|
||||
'x-udid': 'AMAiMrPqqQ2PTnOxAr5M71LCh-dIQ8kkYvw=',
|
||||
},
|
||||
ProcessImage: function(content) {
|
||||
const $ = cheerio.load(content, { xmlMode: true });
|
||||
|
||||
$('img.content_image, img.origin_image, img.content-image').each((i, e) => {
|
||||
if (e.attribs['data-original']) {
|
||||
$(e).attr({
|
||||
src: e.attribs['data-original'],
|
||||
width: null,
|
||||
height: null,
|
||||
});
|
||||
} else {
|
||||
$(e).attr({
|
||||
src: e.attribs.src.replace('_b.jpg', '_r.jpg'),
|
||||
width: null,
|
||||
height: null,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return $.html();
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user