From 6887a0af6705487bd4e31c91d951c34cb848b0de Mon Sep 17 00:00:00 2001 From: dteviot Date: Sun, 17 Sep 2017 09:10:15 +1200 Subject: [PATCH] Only single copy of FanFiction chapters. resolves https://github.com/dteviot/WebToEpub/issues/135 --- plugin/js/parsers/FanFictionParser.js | 14 +++++++++++++- testdata/FanFiction.html | 7 +++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/plugin/js/parsers/FanFictionParser.js b/plugin/js/parsers/FanFictionParser.js index 309a8fee..235e0bd1 100644 --- a/plugin/js/parsers/FanFictionParser.js +++ b/plugin/js/parsers/FanFictionParser.js @@ -21,7 +21,19 @@ class FanFictionParser extends Parser { // no list of chapters found, assume it's a single chapter story return Promise.resolve(that.singleChapterStory(baseUrl, dom)); } else { - return Promise.resolve(options.map(option => that.optionToChapterInfo(baseUrl, option))); + let foundUrls = new Set(); + let isUnique = function(chapterInfo) { + let unique = !foundUrls.has(chapterInfo.sourceUrl); + if (unique) { + foundUrls.add(chapterInfo.sourceUrl); + } + return unique; + } + + return Promise.resolve( + options.map(option => that.optionToChapterInfo(baseUrl, option)) + .filter(isUnique) + ); } } diff --git a/testdata/FanFiction.html b/testdata/FanFiction.html index 7f758e9e..bfe6658d 100644 --- a/testdata/FanFiction.html +++ b/testdata/FanFiction.html @@ -25,6 +25,13 @@

If you're like me, you will have...

+