Henry Wang
2018-09-21 18:39:35 +08:00
committed by DIYgod
parent 675fb3d3ef
commit ca1afeef6a
6 changed files with 36 additions and 10 deletions
+3 -3
View File
@@ -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;
+1 -1
View File
@@ -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}`,
})),
+1 -1
View File
@@ -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,
};
})
+1 -1
View File
@@ -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);
}
+7 -4
View File
@@ -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',
};
}
+23
View File
@@ -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();
},
};