From eab64f3e596b884b8514fb494e0eb6fd9b99962e Mon Sep 17 00:00:00 2001 From: Jeason Lau Date: Sat, 15 Feb 2020 19:02:37 +0800 Subject: [PATCH] fix: ignore the latest chapter when not updated (#3958) --- lib/routes/novel/axdzs.js | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/lib/routes/novel/axdzs.js b/lib/routes/novel/axdzs.js index 3c284fb16..7d462bb21 100644 --- a/lib/routes/novel/axdzs.js +++ b/lib/routes/novel/axdzs.js @@ -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,