fix: ignore the latest chapter when not updated (#3958)

This commit is contained in:
Jeason Lau 2020-02-15 19:02:37 +08:00 committed by GitHub
parent e78bf9ca4a
commit eab64f3e59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 5 deletions

View File

@ -20,13 +20,33 @@ module.exports = async (ctx) => {
const lastChapter = $('.chapter')
.last()
.children();
const chapterUrl = novelUrl + lastChapter.attr('href');
const chapterTitle = lastChapter.text();
const chapterContent = await ctx.cache.tryGet(chapterUrl, async () => {
const lastChapter = await got.get(chapterUrl);
const $ = cheerio.load(lastChapter.data);
const secondChapter = $('.chapter')
.last()
.prev()
.children();
const lastChapterUrl = novelUrl + lastChapter.attr('href');
const secondChapterUrl = novelUrl + secondChapter.attr('href');
const lastChapterContent = await ctx.cache.tryGet(lastChapterUrl, async () => {
const lastChapter = await got.get(lastChapterUrl);
const $ = cheerio.load(lastChapter.data, { decodeEntities: false });
return $('.content').html();
});
// 以下需要判断最新章节是否已填充内容
let chapterTitle, chapterUrl, chapterContent;
// 判断新章节内是否存在无内容的提示信息,如存在则请求上一章节数据
if (lastChapterContent.indexOf('鍦ㄦ洿鏂颁腑锛岃绋嶅悗鍒锋') === -1) {
chapterTitle = lastChapter.text();
chapterUrl = lastChapterUrl;
chapterContent = lastChapterContent;
} else {
chapterTitle = secondChapter.text();
chapterUrl = secondChapterUrl;
chapterContent = await ctx.cache.tryGet(secondChapterUrl, async () => {
const secondChapter = await got.get(secondChapterUrl);
const $ = cheerio.load(secondChapter.data, { decodeEntities: false });
return $('.content').html();
});
}
ctx.state.data = {
title: `爱下电子书-${title}`,
description: description,