fix: /zhihu/zhuanlan undefined title (#6466)

This commit is contained in:
Laam Pui 2020-12-19 00:56:35 +08:00 committed by GitHub
parent 387c23852d
commit 4e2b1fa38c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 4 deletions

View File

@ -22,12 +22,29 @@ module.exports = async (ctx) => {
const item = listRes.data.data.map((item) => {
const $ = cheerio.load(item.content);
$('img').css('max-width', '100%');
let title = '';
let link = '';
let author = '';
let pubDate = '';
if (item.type === 'answer') {
title = item.question.title;
author = item.question.author.name;
link = `https://www.zhihu.com/question/${item.question.id}/answer/${item.id}`;
pubDate = new Date(item.question.created);
} else if (item.type === 'article') {
title = item.title;
link = item.url;
author = item.author.name;
pubDate = new Date(item.created);
}
return {
title: item.title,
link: item.url,
title,
link,
description: $.html(),
pubDate: new Date(item.created),
author: item.author.name,
pubDate,
author,
};
});