From fd66034ba971c31ef645e5b6d1f5b7aef07ab7d9 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Sun, 4 Dec 2022 19:36:27 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=BB=D0=B8=D1=87=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=B2=D0=B0=20=D0=BD=D0=B0=D0=B9=D0=B4=D0=B5=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D1=85=20=D1=80=D0=B5=D0=B7=D1=83=D0=BB=D1=8C=D1=82=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/core/DbSearcher.js | 3 ++- server/core/opds/AuthorPage.js | 27 +++++++++++++++++++++------ server/core/opds/BasePage.js | 2 ++ server/core/opds/SeriesPage.js | 10 ++++++++-- server/core/opds/TitlePage.js | 10 ++++++++-- server/core/utils.js | 1 + 6 files changed, 42 insertions(+), 11 deletions(-) diff --git a/server/core/DbSearcher.js b/server/core/DbSearcher.js index 130c924..0260ab9 100644 --- a/server/core/DbSearcher.js +++ b/server/core/DbSearcher.js @@ -672,10 +672,11 @@ class DbSearcher { const s = row.value.substring(0, depth); let g = group.get(s); if (!g) { - g = {id: row.id, name: row.name, value: s, count: 0}; + g = {id: row.id, name: row.name, value: s, count: 0, bookCount: 0}; group.set(s, g); } g.count++; + g.bookCount += row.bookCount; } const result = Array.from(group.values()); diff --git a/server/core/opds/AuthorPage.js b/server/core/opds/AuthorPage.js index 3d14936..3a4302b 100644 --- a/server/core/opds/AuthorPage.js +++ b/server/core/opds/AuthorPage.js @@ -12,17 +12,22 @@ class AuthorPage extends BasePage { sortBooks(bookList) { //схлопывание серий const books = []; - const seriesSet = new Set(); + const seriesMap = new Map(); for (const book of bookList) { if (book.series) { - if (!seriesSet.has(book.series)) { + let seriesIndex = seriesMap.get(book.series); + if (seriesIndex === undefined) { + seriesIndex = books.length; books.push({ type: 'series', - book + book, + bookCount: 0, }); - seriesSet.add(book.series); + seriesMap.set(book.series, seriesIndex); } + + books[seriesIndex].bookCount++; } else { books.push({ type: 'book', @@ -135,6 +140,10 @@ class AuthorPage extends BasePage { link: this.navLink({ href: `/${this.id}?author=${encodeURIComponent(query.author)}` + `&series=${encodeURIComponent(b.book.series)}&genre=${encodeURIComponent(query.genre)}`}), + content: { + '*ATTRS': {type: 'text'}, + '*TEXT': `${b.bookCount} книг${utils.wordEnding(b.bookCount, 8)} по автору${(query.genre ? ' (в выбранном жанре)' : '')}`, + }, }) ); } else { @@ -170,10 +179,16 @@ class AuthorPage extends BasePage { link: this.navLink({href: `/${this.id}?author=${rec.q}&genre=${encodeURIComponent(query.genre)}`}), }; - if (rec.count) { + let countStr = ''; + if (rec.count) + countStr = `${rec.count} автор${utils.wordEnding(rec.count, 0)}${(query.genre ? ' (в выбранном жанре)' : '')}`; + if (!countStr && rec.bookCount && !query.genre) + countStr = `${rec.bookCount} книг${utils.wordEnding(rec.bookCount, 8)}`; + + if (countStr) { e.content = { '*ATTRS': {type: 'text'}, - '*TEXT': `${rec.count} автор${utils.wordEnding(rec.count, 0)}`, + '*TEXT': countStr, }; } diff --git a/server/core/opds/BasePage.js b/server/core/opds/BasePage.js index e0c19a9..abd12d5 100644 --- a/server/core/opds/BasePage.js +++ b/server/core/opds/BasePage.js @@ -140,6 +140,7 @@ class BasePage { id: row.id, title: (row[from] || 'Без автора'), q: `=${encodeURIComponent(row[from])}`, + bookCount: row.bookCount, }; result.push(rec); @@ -171,6 +172,7 @@ class BasePage { id: row.id, title: row.name, q: `=${encodeURIComponent(row.name)}`, + bookCount: row.bookCount, }; } else { rec = { diff --git a/server/core/opds/SeriesPage.js b/server/core/opds/SeriesPage.js index 66097e0..8134211 100644 --- a/server/core/opds/SeriesPage.js +++ b/server/core/opds/SeriesPage.js @@ -103,10 +103,16 @@ class SeriesPage extends BasePage { link: this.navLink({href: `/${this.id}?series=${rec.q}&genre=${encodeURIComponent(query.genre)}`}), }; - if (rec.count) { + let countStr = ''; + if (rec.count) + countStr = `${rec.count} сери${utils.wordEnding(rec.count, 1)}${(query.genre ? ' (в выбранном жанре)' : '')}`; + if (!countStr && rec.bookCount && !query.genre) + countStr = `${rec.bookCount} книг${utils.wordEnding(rec.bookCount, 8)}`; + + if (countStr) { e.content = { '*ATTRS': {type: 'text'}, - '*TEXT': `${rec.count} сери${utils.wordEnding(rec.count, 1)}`, + '*TEXT': countStr, }; } diff --git a/server/core/opds/TitlePage.js b/server/core/opds/TitlePage.js index f4511f3..9715c3a 100644 --- a/server/core/opds/TitlePage.js +++ b/server/core/opds/TitlePage.js @@ -73,10 +73,16 @@ class TitlePage extends BasePage { link: this.navLink({href: `/${this.id}?title=${rec.q}&genre=${encodeURIComponent(query.genre)}`}), }; - if (rec.count) { + let countStr = ''; + if (rec.count) + countStr = `${rec.count} назван${utils.wordEnding(rec.count, 3)}${(query.genre ? ' (в выбранном жанре)' : '')}`; + if (!countStr && rec.bookCount && !query.genre) + countStr = `${rec.bookCount} книг${utils.wordEnding(rec.bookCount, 8)}`; + + if (countStr) { e.content = { '*ATTRS': {type: 'text'}, - '*TEXT': `${rec.count} назван${utils.wordEnding(rec.count, 3)}`, + '*TEXT': countStr, }; } diff --git a/server/core/utils.js b/server/core/utils.js index 98ff85b..7dc8991 100644 --- a/server/core/utils.js +++ b/server/core/utils.js @@ -184,6 +184,7 @@ function wordEnding(num, type = 0) { ['ок', 'ка', 'ки', 'ки', 'ки', 'ок', 'ок', 'ок', 'ок', 'ок'],//5 ['ых', 'ое', 'ых', 'ых', 'ых', 'ых', 'ых', 'ых', 'ых', 'ых'],//6 ['о', 'о', 'о', 'о', 'о', 'о', 'о', 'о', 'о', 'о'],//7 + ['', 'а', 'и', 'и', 'и', '', '', '', '', ''],//8 ]; const deci = num % 100; if (deci > 10 && deci < 20) {