Browse Source

Улучшил парсинг имени автора из fb2

Book Pauk 6 years ago
parent
commit
37d60bc9b9

+ 15 - 5
client/components/Reader/HistoryPage/HistoryPage.vue

@@ -164,11 +164,21 @@ class HistoryPage extends Vue {
             else
             else
                 title = '';
                 title = '';
 
 
-            let author = _.compact([
-                fb2.lastName,
-                fb2.firstName,
-                fb2.middleName
-            ]).join(' ');
+            let author = '';
+            if (fb2.author) {
+                const authorNames = fb2.author.map(a => _.compact([
+                    a.lastName,
+                    a.firstName,
+                    a.middleName
+                ]).join(' '));
+                author = authorNames.join(', ');
+            } else {
+                author = _.compact([
+                    fb2.lastName,
+                    fb2.firstName,
+                    fb2.middleName
+                ]).join(' ');
+            }
             author = (author ? author : (fb2.bookTitle ? fb2.bookTitle : book.url));
             author = (author ? author : (fb2.bookTitle ? fb2.bookTitle : book.url));
 
 
             result.push({
             result.push({

+ 10 - 6
client/components/Reader/TextPage/TextPage.vue

@@ -377,13 +377,17 @@ class TextPage extends Vue {
                 this.meta = bookManager.metaOnly(this.book);
                 this.meta = bookManager.metaOnly(this.book);
                 this.fb2 = this.meta.fb2;
                 this.fb2 = this.meta.fb2;
 
 
-                const authorName = _.compact([
-                    this.fb2.lastName,
-                    this.fb2.firstName,
-                    this.fb2.middleName
-                ]).join(' ');
+                let authorNames = [];
+                if (this.fb2.author) {
+                    authorNames = this.fb2.author.map(a => _.compact([
+                        a.lastName,
+                        a.firstName,
+                        a.middleName
+                    ]).join(' '));
+                }
+
                 this.title = _.compact([
                 this.title = _.compact([
-                    authorName,
+                    authorNames.join(', '),
                     this.fb2.bookTitle
                     this.fb2.bookTitle
                 ]).join(' - ');
                 ]).join(' - ');
 
 

+ 13 - 3
client/components/Reader/share/BookParser.js

@@ -201,6 +201,12 @@ export default class BookParser {
                 }
                 }
             }
             }
 
 
+            if (elemName == 'author' && path.indexOf('/fictionbook/description/title-info/author') == 0) {
+                if (!fb2.author)
+                    fb2.author = [];
+                fb2.author.push({});
+            }
+
             if (path.indexOf('/fictionbook/body') == 0) {
             if (path.indexOf('/fictionbook/body') == 0) {
                 if (tag == 'body') {
                 if (tag == 'body') {
                     if (!isFirstBody)
                     if (!isFirstBody)
@@ -319,15 +325,19 @@ export default class BookParser {
 
 
             text = text.replace(/[\t\n\r\xa0]/g, ' ');
             text = text.replace(/[\t\n\r\xa0]/g, ' ');
 
 
+            const authorLength = (fb2.author && fb2.author.length ? fb2.author.length : 0);
             switch (path) {
             switch (path) {
                 case '/fictionbook/description/title-info/author/first-name':
                 case '/fictionbook/description/title-info/author/first-name':
-                    fb2.firstName = text;
+                    if (authorLength)
+                        fb2.author[authorLength - 1].firstName = text;
                     break;
                     break;
                 case '/fictionbook/description/title-info/author/middle-name':
                 case '/fictionbook/description/title-info/author/middle-name':
-                    fb2.middleName = text;
+                    if (authorLength)
+                        fb2.author[authorLength - 1].middleName = text;
                     break;
                     break;
                 case '/fictionbook/description/title-info/author/last-name':
                 case '/fictionbook/description/title-info/author/last-name':
-                    fb2.lastName = text;
+                    if (authorLength)
+                        fb2.author[authorLength - 1].lastName = text;
                     break;
                     break;
                 case '/fictionbook/description/title-info/genre':
                 case '/fictionbook/description/title-info/genre':
                     fb2.genre = text;
                     fb2.genre = text;