fix: 豆瓣日记最新回应

This commit is contained in:
nczitzk
2020-10-27 22:45:27 +08:00
parent 164990ffe7
commit 45b3d978b1
+10 -13
View File
@@ -34,25 +34,22 @@ module.exports = async (ctx) => {
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
const commentsConfig = content('script').eq(16).html().replace('var _COMMENTS_CONFIG =', '');
const comments = JSON.parse(commentsConfig.match(/'comments':(.*?)}],/)[1] + '}]');
let title, description, pubDate;
const comments = JSON.parse(detailResponse.data.match(/'comments':(.*)}],/)[1] + '}]');
for (const c of comments) {
if (c.id === item.link.split('#')[1]) {
(title = `${c.author.name} 于 ${c.create_time} 的回应`), (description = c.text);
pubDate = new Date(c.create_time + ' GMT+8').toUTCString();
break;
return {
link: item.link,
title: `${c.author.name} 于 ${c.create_time} 的回应`,
pubDate: new Date(c.create_time + ' GMT+8').toUTCString(),
description: c.text,
author: c.author.name,
};
} else if (c.replies.length > 0) {
comments.push(...c.replies);
}
}
item.title = title;
item.description = description;
item.pubDate = pubDate;
return item;
})
)
);