From c2131e365492adbf00b4b86340dd40481275f954 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Fri, 20 Nov 2020 21:26:16 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BF=D0=B0=D1=80=D1=81=D0=B8=D0=BD=D0=B3=D0=B0?= =?UTF-8?q?=20fb2=20-=20=D1=80=D0=B0=D1=81=D0=BF=D0=BE=D0=B7=D0=BD=D0=B0?= =?UTF-8?q?=D0=B5=D0=BC=20=D1=82=D0=B5=D0=B3=20sequence?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/Reader/share/BookParser.js | 30 +++++++++++++++++++- client/share/utils.js | 14 +++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/client/components/Reader/share/BookParser.js b/client/components/Reader/share/BookParser.js index f368b6be..7c11260f 100644 --- a/client/components/Reader/share/BookParser.js +++ b/client/components/Reader/share/BookParser.js @@ -216,12 +216,32 @@ export default class BookParser { } } - if (tag == 'author' && path.indexOf('/fictionbook/description/title-info/author') == 0) { + if (path == '/fictionbook/description/title-info/author') { if (!fb2.author) fb2.author = []; + fb2.author.push({}); } + const isPublishSequence = (path == '/fictionbook/description/publish-info/sequence'); + if (path == '/fictionbook/description/title-info/sequence' || isPublishSequence) { + if (!fb2.sequence) + fb2.sequence = []; + + if (!isPublishSequence || !fb2.sequence.length) { + const attrs = sax.getAttrsSync(tail); + const seq = {}; + if (attrs.name && attrs.name.value) { + seq.name = attrs.name.value; + } + if (attrs.number && attrs.number.value) { + seq.number = attrs.number.value; + } + + fb2.sequence.push(seq); + } + } + if (path.indexOf('/fictionbook/body') == 0) { if (tag == 'body') { if (isFirstBody && fb2.annotation) { @@ -233,6 +253,14 @@ export default class BookParser { newParagraph(' ', 1); } + if (isFirstBody && fb2.sequence && fb2.sequence.length) { + const bt = utils.getBookTitle(fb2); + if (bt.sequence) { + newParagraph(bt.sequence, bt.sequence.length); + newParagraph(' ', 1); + } + } + if (!isFirstBody) newParagraph(' ', 1); isFirstBody = false; diff --git a/client/share/utils.js b/client/share/utils.js index 7e440799..1c3af291 100644 --- a/client/share/utils.js +++ b/client/share/utils.js @@ -336,8 +336,18 @@ export function getBookTitle(fb2) { result.author = authorNames.join(', '); } - if (fb2.bookTitle) - result.bookTitle = fb2.bookTitle; + if (fb2.sequence) { + const seqs = fb2.sequence.map(s => _.compact([ + s.name, + (s.number ? `#${s.number}` : null), + ]).join(' ')); + + result.sequence = seqs.join(', '); + if (result.sequence) + result.sequenceTitle = `(${result.sequence})`; + } + + result.bookTitle = _.compact([result.sequenceTitle, fb2.bookTitle]).join(' '); result.title = _.compact([ result.author,