diff --git a/routes/zhihu/activities.js b/routes/zhihu/activities.js
index d0a95c1aa1..9eb15ef078 100644
--- a/routes/zhihu/activities.js
+++ b/routes/zhihu/activities.js
@@ -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;
diff --git a/routes/zhihu/answers.js b/routes/zhihu/answers.js
index bd1a232f4e..21df7d7e95 100644
--- a/routes/zhihu/answers.js
+++ b/routes/zhihu/answers.js
@@ -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}`,
})),
diff --git a/routes/zhihu/collection.js b/routes/zhihu/collection.js
index 15b4cc5388..4c30447e93 100644
--- a/routes/zhihu/collection.js
+++ b/routes/zhihu/collection.js
@@ -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,
};
})
diff --git a/routes/zhihu/daily.js b/routes/zhihu/daily.js
index 0dfa673131..b12475cffb 100644
--- a/routes/zhihu/daily.js
+++ b/routes/zhihu/daily.js
@@ -36,7 +36,7 @@ module.exports = async (ctx) => {
Referer: url,
},
});
- item.description = storyDetail.data.body.replace(/
([\s\S]*?)<\/div>/g, '
$1');
+ item.description = utils.ProcessImage(storyDetail.data.body.replace(/
([\s\S]*?)<\/div>/g, '$1'));
ctx.cache.set(key, item.description, 24 * 60 * 60);
}
diff --git a/routes/zhihu/hotlist.js b/routes/zhihu/hotlist.js
index b9d6399b4f..7556b47d3a 100644
--- a/routes/zhihu/hotlist.js
+++ b/routes/zhihu/hotlist.js
@@ -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}的回答
${item.target.content}`,
+ author: item.target.author.name,
+ description: `${item.target.author.name}的回答
${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}的文章
${item.target.content}`,
- pubDate: new Date(item.created_time).toUTCString(),
+ author: item.target.author.name,
+ description: `${item.target.author.name}的文章
${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',
};
}
diff --git a/routes/zhihu/utils.js b/routes/zhihu/utils.js
index b4b35c56c2..7eb086ae71 100644
--- a/routes/zhihu/utils.js
+++ b/routes/zhihu/utils.js
@@ -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();
+ },
};